Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic ReactiveUserControl "cannot be edited in Design view"

I changed my UserControl to be a ReactiveUserControl and now I can't view the Design View. Is there anything I can do to get the designer to work with ReactiveUserControl?

like image 514
Brian Jenkins Avatar asked May 07 '18 17:05

Brian Jenkins


1 Answers

The Visual Studio designer has issues when your control or window directly inherits from a generic class. This was a pretty common issue with WinForms as well. You can work around this issue by defining another non-generic class that sits between the generic ReactiveUserControl and your control:

public partial class MyUserControl : MyUserControlBase
{
    public MyUserControl()
    {
        InitializeComponent();
    }
}

public abstract class MyUserControlBase: ReactiveUserControl<MyUserControlViewModel>
{
}

In the XAML, our root object element is defined as the base element (MyUserControlBase) and its class declaration is connected to the partial class defined above (MyUserControl):

<myNameSpace:MyUserControlBase
    x:Class="MyNameSpace.MyUserControl"
    xmlns:myNameSpace="clr-namespace:MyNameSpace"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
like image 139
Eugene Pawlik Avatar answered Sep 23 '22 15:09

Eugene Pawlik