C# 数据绑定项控件以列出WPF
我正在努力完成我第一次真正的WPF冒险 我的XAML如下所示:C# 数据绑定项控件以列出WPF,c#,wpf,xaml,C#,Wpf,Xaml,我正在努力完成我第一次真正的WPF冒险 我的XAML如下所示: <ItemsControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Name="ImageList" x:FieldModifier="private" ItemsSource="{Binding Source= images }"> <ItemsControl.ItemsPanel>
<ItemsControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Name="ImageList" x:FieldModifier="private" ItemsSource="{Binding Source= images }">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- The Image binding -->
<TextBox Text="{Binding Key}" MouseDoubleClick="Control_OnMouseDoubleClick"></TextBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我的C#是:
var ll=new LocalDataHandler();
var data=ll.FetchContentByContentType(
新字符串[]{“电影”,“电视”},0);
列表图像=数据。选择(
contentItem=>new KeyValuePair(contentItem.ContentName,
contentItem.ContentId.ToString(
CultureInfo.InvariantCulture)).ToList();
ImageList.ItemsSource=图像;
ImageList中填充了我想要的所有内容,但由于某些原因,我的表单上没有显示任何内容。尝试将TeextBox的绑定模式设置为OneWay
<TextBox Text="{Binding Key, Mode=OneWay}" MouseDoubleClick="Control_OnMouseDoubleClick"></TextBox>
因为您正在代码隐藏中设置ItemsSource。。不需要ItemsSource=“{Binding Source=images}”,因为它是错误代码。。。删除输出窗口中xamlCheck中的ItemsSource属性,查看是否找到Key
属性。你在评论中提到了图像绑定,但我看到的只是一个文本框,我已经填充了Key和Value。但我的XAML说它找不到密钥。我尝试了ImageList.Key,但还是什么都没有。@它被删除了,但没有更改。感谢您的帮助。将静态键值对添加到您的列表中,看看会发生什么
<TextBox Text="{Binding Key, Mode=OneWay}" MouseDoubleClick="Control_OnMouseDoubleClick"></TextBox>