Generic ReactiveUserControl "cannot be edited in Design view"
Asked Answered
R

1

8

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?

Refrigeration answered 7/5, 2018 at 17:17 Comment(0)
S
13

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">
Springtail answered 7/5, 2018 at 17:49 Comment(1)
Just to add after editing you may get a "The name "MyUserControlBase" does not exist in namespace "clr-namespace:********". Make sure and rebuild project after changes.Scholium

© 2022 - 2024 — McMap. All rights reserved.