在WPF中获取列表视图的复选框值
我有这样的代码
<ListView ItemsSource="{Binding}" Height="110.277" Margin="4,0,3,-138" Name="listView1" VerticalAlignment="Bottom">
<ListBox.ItemTemplate>
<DataTemplate>
<!--<TextBlock Text="{Binding Path=Name}" Width="100" />-->
<!--<CheckBox IsChecked="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" Width="100"/>-->
<CheckBox Name="chk1" Content="{Binding Path=Name}" IsChecked="{Binding IsPersonChecked}" Checked="checked_accname" Width="100" />
</DataTemplate>
</ListBox.ItemTemplate>
,在其中我将在按钮单击事件中从数据库动态绑定复选框的值,但我无法获取列表视图的选中复选框的值。
请帮助我解决这个问题。提前致谢
I am having the code like
<ListView ItemsSource="{Binding}" Height="110.277" Margin="4,0,3,-138" Name="listView1" VerticalAlignment="Bottom">
<ListBox.ItemTemplate>
<DataTemplate>
<!--<TextBlock Text="{Binding Path=Name}" Width="100" />-->
<!--<CheckBox IsChecked="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" Width="100"/>-->
<CheckBox Name="chk1" Content="{Binding Path=Name}" IsChecked="{Binding IsPersonChecked}" Checked="checked_accname" Width="100" />
</DataTemplate>
</ListBox.ItemTemplate>
In which I will bind the value for checkbox dynamically from db at buttonclick event I can't able to get the value of checked checkbox of listview.
Please help me regarding this. Thanks in Advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要尝试从 UI 获取检查的值。使用数据对象中的 IsPersonChecked 属性。
编辑
在了解您使用了 DataView 之后,您的查询将如下所示:
Do not try to get the checked value from the UI. Use the IsPersonChecked property from the data object.
EDIT
After understanding that you used a DataView your query would be something like this: