WPF Trigger based on Object Type

前端 未结 5 938
自闭症患者
自闭症患者 2020-12-13 17:27

Is there a way to do a comparison on object type for a trigger?


         


        
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 18:07

    If you are in a position to modify the (base) type assigned to 'SelectedItem' by adding the property:

    public Type Type => this.GetType();
    

    Then you could use the DataTrigger in xaml like this:

    
    
    

    Advantage compared to AndyG's good answer is, that you do not have a magic string of your type in XAML, but have everything compile safe. Disadvantage: You need to modify your model - which might not always be possible.

提交回复
热议问题