Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.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# 无法使用列表中的条目填充复选框<&燃气轮机;_C#_Wpf_Wpftoolkit_Checkboxlist_Xceed - Fatal编程技术网

C# 无法使用列表中的条目填充复选框<&燃气轮机;

C# 无法使用列表中的条目填充复选框<&燃气轮机;,c#,wpf,wpftoolkit,checkboxlist,xceed,C#,Wpf,Wpftoolkit,Checkboxlist,Xceed,我有以下XML,从中获取ID并填充到列表中: <TestCase ID="TEST"> <Frames> <Frame>ff</Frame> <Frame>ff 53</Frame> </Frames> </TestCase> 我创建复选框的Xaml如下所示 <xctk:CheckListBox x:Name="ListBox_TestCase"

我有以下XML,从中获取ID并填充到列表中:

<TestCase ID="TEST">
   <Frames>
     <Frame>ff</Frame>
     <Frame>ff 53</Frame>
   </Frames>
</TestCase>
我创建复选框的Xaml如下所示

<xctk:CheckListBox x:Name="ListBox_TestCase"
                   ItemsSource="{Binding AvailableFrames}"
                   SelectedMemberPath="{Binding IsChecked}"
                   SelectedValue="{Binding Name}"/>
但是,我无法获取列表
AvailableFrames
来填充复选框列表项的“Name”条目。它以某种方式获取条目的数量(在我的例子中是5个),并填充5个空的检查表项,但是“ID”中的名称或值没有反映出来

为什么
列表中的值不出现在
复选框列表中?我猜我有一个约束问题

请给我一些建议

截图:

您以错误的方式填充了
SelectedMemberPath
SelectedValue
属性。请尝试以下操作,而不是使用
{Binding}
语法:

<xctk:CheckListBox ... ItemsSource="{Binding AvailableFrames}" SelectedMemberPath="IsChecked" DisplayMemberPath="Name" ValueMemberPath="Id"/>

看起来像“现代UI”或mui不支持复选框。当我从我的项目中删除mui接口时,我可以让它正常工作

我们还可以为每个条目创建一个列表框,如下所示,这是现代UI支持的

<ListBox x:Name="ListBox_TestCase" ItemsSource="{Binding AvailableFrames}" Margin="172,10,283,15" >
    <ListBox.ItemTemplate>
        <HierarchicalDataTemplate>
            <CheckBox x:Name="CheckBox_TestCase" Content="{Binding Name}" IsChecked="{Binding IsChecked}"/>
        </HierarchicalDataTemplate>
    </ListBox.ItemTemplate>
</ListBox>


谢谢你的建议,但这也没用
对不起,我把
ValueMemberPath
displaymberpath
搞错了。。。请看我更新的答案,对我有用!顺便说一下,您可以从XAML代码中删除
ItemsSource=“{Binding AvailableFrames}”
部分,因为您正在代码中设置列表框“
ItemSource
”。。。(然而,这不应该影响显示问题,正如旁注)似乎没有区别,我仍然从列表中得到一个空条目
好吧,对于
列表中的硬编码项,它对我来说很好,所以我怀疑从XML文件填充列表时出错了。。。请在
ListBox\u TestCase.ItemsSource=AvailableFrames设置断点
并检查
可用字段的内容
?它是否真的包含5个项目,并且这5个项目的
Name
属性是否包含字符串值?您是否查看了by Xceed?您是指这里的项目,是的,我有。不是,我在注释中链接的项目。这是Xceeds WPF Toolkit的live explorer演示。请确保实现Equals和GetHashCode方法。否则,复选框可能会出现问题。
<xctk:CheckListBox ... ItemsSource="{Binding AvailableFrames}" SelectedMemberPath="IsChecked" DisplayMemberPath="Name" ValueMemberPath="Id"/>
<ListBox x:Name="ListBox_TestCase" ItemsSource="{Binding AvailableFrames}" Margin="172,10,283,15" >
    <ListBox.ItemTemplate>
        <HierarchicalDataTemplate>
            <CheckBox x:Name="CheckBox_TestCase" Content="{Binding Name}" IsChecked="{Binding IsChecked}"/>
        </HierarchicalDataTemplate>
    </ListBox.ItemTemplate>
</ListBox>