我正在嘗試創建一個從Xaml創建的DependencyObject
。 它具有像這樣定義List<object>
類型的DependencyProperty
:如何在UWP中爲集合類型定義`DependencyProperty`?
public List<object> Map
{
get { return (List<object>)GetValue(MapProperty); }
set { SetValue(MapProperty, value); }
}
// Using a DependencyProperty as the backing store for Map. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MapProperty =
DependencyProperty.Register("Map", typeof(List<object>), typeof(MyConverter), new PropertyMetadata(null));
的Xaml:
<MyConverter x:Key="myConverter">
<MyConverter.Map>
<TextPair First="App.Blank" Second ="App.BlankViewModel"/>
</MyConverter.Map>
</MyConverter>
我不斷接收Cannot add instance of type 'UwpApp.Xaml.TextPair' to a collection of type 'System.Collections.Generic.List<Object>
。 什麼會導致此錯誤?謝謝。
此錯誤的原因很簡單:您定義了類型爲'List
@Fruchtzwerg,我試過你的暗示,但它仍然失敗。 –
我很困惑,因爲我沒有提出任何建議。那麼你嘗試了什麼? – Fruchtzwerg