datatrigger on enum to change image

后端 未结 3 1500
小蘑菇
小蘑菇 2020-12-04 11:21

I\'ve got a button with a fixed background image and would like to show a small overlay image on top of it. Which overlay image to chose depends on a dependency property (

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 11:48

    Complete worked example for WPF + MVVM.

    Tested on MSVC 2017.

    In the view:

    
        
            
        
    
    

    If using ReSharper, and if the DataContext is set up properly, there will be intellisense when you hit the . after StatusIcon, i.e. it will show the properties of the enum which are Debug, Info, Warning or Error.

    If using ReSharper, it will suggest the following update to the namespace in the header for the XAML file(its good like that):

    xmlns:my="clr-namespace:Class.Path.MyViewModel;assembly=MyAssembly"
    

    And the VieModel:

    public enum StatusIcon
    {
        Debug,
        Info,
        Warning,
        Error
    }
    
    public class MyViewModel
    {
        public StatusIcon StatusIcon { get; }
    }
    

    We also use Fody for automated binding.

提交回复
热议问题