2013-07-09 37 views
0

在下面的代碼片段:在XAML中,EnumHelper.Enum屬性的含義是什麼?

<ItemsControl helpers:EnumHelper.Enum="order:TShirtSizeEnum" ... > 
... 
</ItemsControl> 

什麼助手:EnumHelper.Enum屬性意味着什麼?

接下來是實現EnumHelper類

public class EnumHelper : DependencyObject 
{ 
    public static Type GetEnum(DependencyObject obj) 
    { 
     return (Type)obj.GetValue(EnumProperty); 
    } 

    public static void SetEnum(DependencyObject obj, string value) 
    { 
     obj.SetValue(EnumProperty, value); 
    } 

    // Using a DependencyProperty as the backing store for Enum. This enables animation, styling, binding, etc... 
    public static readonly DependencyProperty EnumProperty = 
     DependencyProperty.RegisterAttached("Enum", typeof(Type), typeof(EnumHelper), new PropertyMetadata(null, OnEnumChanged)); 

    private static void OnEnumChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) 
    { 
     var control = sender as ItemsControl; 

     if (control != null) 
     { 
      if (e.NewValue != null && e.NewValue as Type != null) 
      { 
       var _enum = Enum.GetValues(e.NewValue as Type); 
       control.ItemsSource = _enum; 
      } 
     } 
    } 
} 
+0

請同時在名稱空間幫助器中聲明類調用EnumHelper的內容,並在該xaml的頂部聲明。應該有'xmlns:helpers =「clr-namespace:(....)」''檢查命名空間 – saamorim

回答

2

推測爲attached property。它的作用取決於什麼helpers所指的(因爲它可能不是.NET的一部分,我不能告訴你任何關於它的東西,但我猜測它使用反射來獲取枚舉值並將它們設置爲ItemsSource)。

2

看起來它意味着:找到EnumHelper類以上爲helpers引用的命名空間。這個類定義了一個附加屬性Enum。將此對象的附加屬性值設置爲...

相關問題