How can I use enum types in XAML?

后端 未结 2 1683
庸人自扰
庸人自扰 2020-12-05 02:26

I\'m learning WPF and I encountered the following problem:

I have an enum type in another namespace than my XAML:

 public enum NodeType
 {
    Type_SYS         


        
2条回答
  •  囚心锁ツ
    2020-12-05 02:58

    You just need to make sure that your namespace is accounted-for in your XAML header then you can reference both custom DPs and enum values directly in your markup.

    For example I use this code to do just that:

    
      
        
          
          
        
        
          
        
      
    
    

    Note that you can't access DataTriggers in a Style, you need to instead make a DataTemplate or ControlTemplate for that (however, .NET 4 adds the ability to set triggers in styles). You can override the ControlTemplate from a Style like so:

    
    

    For DataTemplates you want to have bindings to an object, you can simply use a ContentPresenter and set its content to the object you want to display along with a DataTemplate definition to use for display of the object. There's always a way to use DataTriggers it's just not always direct or as simple as using a Style.

提交回复
热议问题