How can I specify resources in an MVVM view model?

后端 未结 2 1198
天命终不由人
天命终不由人 2021-02-03 10:26

Suppose I want to show list of objects where each object should have a name and a suitable image (for example MenuItems with Icons, or buttons with text and image).

All

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-03 11:04

    There's a bug in custom MarkupExtensions that doesn't allow you to use them in an attribute like that.

    Workaround 1: Declare the attribute as an element, like so:

    
        
            
        
    
    

    Workaround 2: If you precompile the MarkupExtension by putting it in another assembly and referencing it, then it works again. This might be why you're seeing it work in the main window, but not in your DataTemplate.

提交回复
热议问题