2017-04-05 101 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 –