WPF: Reapply DataTemplateSelector when a certain value changes

后端 未结 5 1884
Happy的楠姐
Happy的楠姐 2020-12-10 23:55

So here is the XAML that I have:



        
5条回答
  •  情深已故
    2020-12-11 00:34

    Returning back to your original solution and the problem of "the template selector doesn't get reapplied": you can refresh your view like that

    CollectionViewSource.GetDefaultView(YourItemsControl.ItemsSource).Refresh();
    

    where for brevity sake your ItemsControl is referenced by its name ("YourItemsControl") added to your XAML:

    
    

    The only problem may be how to choose right place in your project for this refresh instruction. It could go into a view code-behind, or, if your IsLeaf is a DP, the right place would be a dependency-property-changed callback.

提交回复
热议问题