Is there a way to resolve a no parameterless constructor error on a custom User Control?

Viewed 1703

I have a Wpf application that has abstract base classes for a certain subset of views, and their corresponding view models as seen here:

 public abstract class BaseForm<TViewModel> : UserControl, IBaseForm where TViewModel: BaseViewModel
{
    protected BaseForm(TViewModel viewModel)
    {
        DataContext = viewModel;
    }

    private TViewModel ViewModel
    {
        get { return DataContext as TViewModel; }
    }

    //Left out remaining implementation details 
}

 public abstract class BaseViewModel : ViewModelBase, IDisposable, IActiveAware, IDocumentContent, IStateAware
{
    //Left out implementation details
}

This application is using the composition root pattern, so the views are created on demand when a user action requires the view to be opened, hence the lack of a parameterless constructor.

For the most part this setup works just fine, everything compiles and the application runs.

However when checking the output window I can in fact see that the implementations of BaseForm are throwing the following exception:

Type 'BaseForm' is not usable as an object element because it is not public or does not define a public parameterless constructor or type converter.

Here is a sample of an implementation:

<forms:BaseForm x:TypeArguments="viewModels:ProjectManagementViewModel" x:Class="MyProject.ProjectManagement"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:forms="clr-namespace:Eka.Common.Wpf.Forms;assembly=Eka.Common.Wpf"
         xmlns:viewModels="clr-namespace:MyProject.ViewModels"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<Grid>

</Grid>

public partial class ProjectManagement
{
    public ProjectManagement(ProjectManagementViewModel viewModel) : base(viewModel)
    {
        InitializeComponent();
    }
}

Is there any way to modify my classes to remove this error?

Edit:

As per my comment this issue seems to be a bit of a phantom, I had some compile errors in my unit test project that I had been ignoring and upon resolving, these errors also disappeared and I've only seen them again when trying to resolve other designer errors but not consistently.

0 Answers
Related