Avalon Dock 2.0 LayoutItemTemplateSelector given ContentPresenter instead of ViewModel

前端 未结 1 1013
遇见更好的自我
遇见更好的自我 2021-01-06 03:13

I\'ve been at this for weeks...I am creating a WPF application that uses Avalon Dock 2.0 in the the Main Window. I am trying to use the Docking Manager in a MVVM way, so I h

相关标签:
1条回答
  • 2021-01-06 04:02

    Change the definition for SelectTemplate on TestTemplateSelector as follows:

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            //check if the item is an instance of TestViewModel
            if (item is TestViewModel)
                return TheTemplate;
    
            //delegate the call to base class
            return base.SelectTemplate(item, container);
        }
    

    You should always check if the item passed is an instance of your target view model and if isn't, delegate the call to the base class so WPF can handle the objects you don't care about.

    0 讨论(0)
提交回复
热议问题