[英]XAML markup error when binding List<string> to a ComboBox ItemSource in a WPF
我正在嘗試在 WPF 應用程序中實現 MVVM,但遇到了一個奇怪的問題,其中List<string>
顯然被視為string
並破壞了 XAML 設計器。
來自 XAML:
<ComboBox Grid.Row="0"
Grid.Column="1"
Name="ServerListComboBox"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Margin="10"
Padding="5"
ItemsSource="Bind ServerList"/>
從視圖模型:
public List<string> ServerList
{
get { return model.ServerList; }
set
{
model.ServerList = value;
OnPropertyChange(nameof(ServerList));
}
}
從模型:
public List<string> ServerList { get; set; }
設計者說Invalid Markup並產生這個錯誤:
錯誤 XDG0028 “IEnumerable”的 TypeConverter 不支持從字符串轉換。
很明顯,它是一個List<string>
而不是string
,編譯很好,但我不能再使用 XAML 設計器了。 有什么我忽略的簡單東西可以讓設計師再次工作嗎? 感謝您的任何建議、提示或幫助
改變:
ItemsSource="Bind ServerList"
到:
ItemsSource="{Binding ServerList}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.