【发布时间】:2018-06-22 19:12:17
【问题描述】:
我正在尝试在列表视图中为列表视图中的所有可用项目添加一个复选框,所以我这样做了:
<ListView x:Name="Playing" ItemsSource="{Binding Source={StaticResource GroupedItems}}"
SelectionChanged="Playing_SelectionChanged" SelectionMode="Single">
<ListView.View>
<GridView AllowsColumnReorder="False" >
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path = IsFavourite}"
Checked="CheckBoxMatch_Checked"
Unchecked="CheckBoxMatch_UnChecked"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="{DynamicResource date}" Width="150" DisplayMemberBinding="{Binding Path = MatchDate}"/>
问题是该复选框仅显示在列表视图中的一项,为什么?
【问题讨论】:
-
发布更多代码。您的 xaml 向我显示每个项目的复选框。
-
同时发布您的 .cs 代码
-
@Milan 我应用了这种样式:pastebin.com/qqdLWDF4 使用
<CheckBox IsChecked="{Binding Path = IsFavourite}" Checked="CheckBoxMatch_Checked" Unchecked="CheckBoxMatch_UnChecked" Style="{StaticResource CheckBoxStar}"/>如果我删除了复选框出现的样式,为什么没有样式? -
不要通过外部 URL 发布代码,而是编辑您的原始帖子。您的风格是在选中
CheckBox时设置Content属性,但在未选中时则不会。此外,自从我使用 WPF ListView 已经有一段时间了(我主要使用第三方组件),但请检查 DataTemplate 的 DataContext 是否是您的底层 ViewModel,就像我正在使用的第三方组件一样不是。 -
@RogerLeblanc 他有一个 ischecked=false 的多数据触发器