我有一個依賴屬性的用戶控件是一個枚舉。我綁定到它並將其設置在主窗口視圖中,但它不會更改。枚舉依賴屬性永遠不會從視圖更新
這是用戶控件和圖標是枚舉
<local:GoogleMaterialIcon Icon="AccountBalance"/>
這裏是枚舉
public enum Icon
{
_3DRotation,
Accessibility
};
這裏是DP
/// <summary>
/// Dependency Property used to back the <see cref="Icon"/> Property
/// </summary>
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register("Icon",
typeof(Icon),
typeof(GoogleMaterialIcon),
new PropertyMetadata(null));
最後的財產
public Icon Icon
{
get { return (Icon)GetValue(IconProperty); }
set
{
SetValue(IconProperty, value);
}
}
我在設置圖標中放置了一個斷點,但它永遠不會運行。枚舉也在它自己的文件中。我每次運行它表明我錯了圖標,因爲DP恢復到第一個枚舉和永遠不會更新
更新:背後
public partial class GoogleMaterialIcon : UserControl
{
/// <summary>
/// Dependency Property used to back the <see cref="Icon"/> Property
/// </summary>
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register("Icon",
typeof(Icon),
typeof(GoogleMaterialIcon),
new PropertyMetadata(null));
/// <summary>
/// Constructor
/// </summary>
public GoogleMaterialIcon()
{
InitializeComponent();
}
/// <summary>
/// Select a predefined icon to use
/// </summary>
public Icon Icon
{
get { return (Icon)GetValue(IconProperty); }
set
{
SetValue(IconProperty, value);
}
}
}
添加了usercontrol的後面代碼。我不使用視圖中的屬性呢。這個想法是在你缺少PropertyChanged-Event的'PropertyMetadata'中的圖標 – Sam
的設置器中執行某些操作。哦,你實際上應該**將你的財產綁定到正確的類型。不僅設置字符串 – lokusking
我不必正常添加。這是一個特殊的枚舉? – Sam