How can i specify a designer datacontext for a style, so Resharper finds my properties?

雨燕双飞 提交于 2019-12-02 18:39:47

@lhildebrandt's answer is generally right, but in my case this solution produces errors that totally disable displaying the view in designer. Specifying <d:Style.DataContext> inside <Style> tag helped me.

<Style>
    <d:Style.DataContext>
        <x:Type Type="local:MyTreeItem" />
    </d:Style.DataContext>
    <!--usual setters, triggers, etc.-->
</Style>

In this way d:DataContext can also be specified for controls, and we can provide it interfaces, nested classes and even generics without any errors: https://stackoverflow.com/a/46637478/5598194

lhildebrandt

Have you tried:

    <Style TargetType="TreeViewItem" d:DataContext="{d:DesignInstance     
 test:TestItemViewModel}">

Atleast for me the properties are highlighted and shown with IntelliSense in VS 2015 and R#9.

Seems to be an identical solution to Specify datacontext type on listbox ItemContainer in style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!