[英]Display a dictionary in a list box
我正在嘗試在WPF的列表框中顯示字典,但出現一些錯誤,無法弄清。 這是我的列表框:
<ListBox x:Name="lstPrice" Grid.Column="3" HorizontalAlignment="Left" Height="75" Margin="25.714,225,0,0" VerticalAlignment="Top" Width="190"/>
這是在我的課程之一中定義的字典:
Dictionary<double, ProdType> prices = new Dictionary<double, ProdType>()
{
{5.4 , ProdType.Plain}; }
在這里,我嘗試將它們綁定到窗口的已加載事件中:
lstPrice.ItemsSource = new BindingSource(prices, null);
錯誤CS0246找不到類型或名稱空間名稱'BindingSource'(是否缺少using指令或程序集引用?)
錯誤CS0103當前上下文中不存在名稱“價格”
在WTF中還有BindingSource的替代方法嗎? 我做錯了什么?
直接指定為lstPrice.ItemsSource = prices
然后使用Item模板中的Value
屬性將其綁定。
例如。
<ListBox SelectedValuePath="Value">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.