How to make IDE recognize View-ViewModel binding in MVVM at design time?

376 views Asked by At

In my application, I bind Views to ViewModels via a central ResourceDictionary in my App.xaml, like this:

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="_styles/SomeStyle.xaml" />
                ...
                <ResourceDictionary>
                    <DataTemplate DataType="{x:Type viewModels:MyViewModel}">
                        <views:MyView />
                    </DataTemplate>
                    ...
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

This works fine. However, the IDE (both Visual Studio with ReSharper and Rider) doesn't recognize the bindings in the views, so e.g. renaming properties is dangerous.

How can I make the IDE recognize the bindings?

1

There are 1 answers

1
Lana On BEST ANSWER

Add to your window or user control. For using IsDesignTimeCreatable=True you have to have parameterless constructor.

d:DataContext="{d:DesignInstance Type=local:YourVm, IsDesignTimeCreatable=True}"