WPF use binding to assign static resource

前端 未结 2 1323
一向
一向 2021-02-12 13:16

I am trying to use an enum to display a corresponding image. For this I have a value converter that converts an enum to the correct resource name. My resources are defined as fo

2条回答
  •  独厮守ぢ
    2021-02-12 13:40

    I would return the resource in the converter:

    
    

    In your converter do something like this:

    return Application.Current.FindResource("AlarmCat1") as BitmapImage;
    

    Set your resources for the complete application with the use of resourcedictionary (app.xaml)

    
        
            
                
            
        
    
    

    In your Dictionary (Dictionary1.xaml)

    
    

    Because your resources are now defined on applicationlevel, the code will now find your resource and give it back.

提交回复
热议问题