2017-04-05 131 views
-1

自己的枚举返回NULL我有这样的代码:WPF DataTrigger - 在XAML

的.xaml:

<DataTrigger Binding="{Binding Path=TypeItem}" Value="{x:Static local:CListBoxItem+ETypeItem.File}"> 
    ... 
</DataTrigger> 

的.cs:

public CListBoxItem(ETypeItem _type) 
{ 
    this.TypeItem = _type; 
    InitializeComponent(); 
} 

... 

public enum ETypeItem { File, Directory } 

... 

public static readonly DependencyProperty TypeItemProperty = 
     DependencyProperty.Register("TypeItem", typeof(ETypeItem), typeof(CListBoxItem), new PropertyMetadata(ETypeItem.Directory)); 
public ETypeItem TypeItem 
{ 
    get { return (ETypeItem) GetValue(TypeItemProperty); } 
    set { SetValue(TypeItemProperty, value); } 
} 

当我运行的应用程序我的风格不工作。当我使用:

<DataTrigger Binding="{Binding Path=TypeItem}" Value="{x:Null}"> 
    ... 
</DataTrigger> 

然后工作..如何使TypeItem加载自己的风格?

回答

0

如果CListBoxItem类源自ListBoxItemControl尝试Trigger代替DataTrigger(和静态值Value="{x:Static local:CListBoxItem+ETypeItem.File}")。 DataTrigger在DataContext中搜索属性,而不是在对象本身中搜索。

+0

非常感谢。这项工作:D –