[英]Unable to create a Collection Type Dependency Property
我正在嘗試創建一個具有對象列表的自定義列表。 雖然在Xaml和后面的代碼中都設置了此選項,但我得到了“錯誤的標記錯誤”。 下面是我如何設置PropertyKey和Property。
private static readonly DependencyPropertyKey ItemSourcePropertyKey = DependencyProperty.RegisterReadOnly(
"ItemSource",
typeof(List<object>),
typeof(MultiSelectComboBox),
new FrameworkPropertyMetadata(null));
public static readonly DependencyProperty ItemSourceProperty = ItemSourcePropertyKey.DependencyProperty;
字段是:
public List<object> ItemSource
{
get { return (List<object>)this.GetValue(ItemSourceProperty); }
set { this.SetValue(ItemSourceProperty, value); }
}
我得到的錯誤是:
{"Cannot create instance of 'Window1' defined in assembly 'GroupExpansion, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Window1.xaml' Line 1 Position 9."}
之前有沒有人將DependencyProperty綁定到列表? 我遇到過一些教程,但是當我嘗試模仿這些教程時,它只是表面上的。 列表和屬性在擴展UserControl的文件中。 如果您需要更多詳細信息,請詢問。 我已經連續幾天不習慣敲鍵盤了。 似乎正在轉圈。
干杯
找到了解決方案,似乎依賴項屬性需要附加到ObservableCollection。 然后,為了進行綁定,它必須是非只讀的,以便可以刪除DependencyPropertyKey並僅將其替換為DependencyProperty。 如果有人為此設置了實際頁面,那將非常有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.