所以我創建了一個用戶控件,並且我在它上面創建了一個依賴屬性TestProperty。UWP XAML用戶控件靜態屬性與實例屬性
我希望有2個此用戶控件的實例併爲每個實例設置TestProperty爲不同的值。
<widgets:mycontrol Test="val1"></widgets:WTComboBox>
<widgets:mycontrol Test="val2"></widgets:WTComboBox>
如果我創建testproperty爲靜態的DependencyProperty如下:
public static readonly DependencyProperty TestProperty=
DependencyProperty.Register("Test", typeof(string), typeof(mycontrol), null);
在控制
,那麼顯然我不能在每個實例的一個不同的值,但是當我創建testproperty作爲一個正常的實例屬性
public DependencyProperty TestProperty;
public mycontrol()
{
TestProperty = DependencyProperty.Register("Test", typeof(string), typeof(mycontrol), null);
}
上的控制,那麼設計師不能識別屬性存在,並創建一個錯誤,但在運行時控制完美的作品一nd控件的每個實例都具有測試屬性的正確值。
所以問題是我如何獲得實例dependencyproperty的工作在設計器?
感謝