Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数据绑定项控件以列出WPF_C#_Wpf_Xaml - Fatal编程技术网

C# 数据绑定项控件以列出WPF

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>

我正在努力完成我第一次真正的WPF冒险

我的XAML如下所示:

    <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>