无法将CheckBox添加到所有行

时间:2018-01-13 15:20:06

标签: c# wpf

我正在尝试在listView中为列表视图中的所有项添加一个CheckBox,所以我这样做了:

<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}"/>

问题是该复选框仅针对列表视图中的一个项目显示,为什么?

1 个答案:

答案 0 :(得分:1)

替换你的

<Setter Property="Content">
     <Setter.Value>
          <Image Source="{StaticResource StarEmpty}"/>
      </Setter.Value>
</Setter>

<Setter Property="ContentTemplate">
     <Setter.Value>
          <DataTemplate>
              <Image Source="{StaticResource StarEmpty}"/>
          </DataTemplate>
      </Setter.Value>
</Setter>

与您的其他触发器相同:

<Trigger Property="IsChecked" Value="True">
                                    <Setter Property="Content">
                                        <Setter.Value>
                                            <Image Source="{StaticResource Star}"/>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="ToolTip" Value="{DynamicResource removeFromFavourite}"/>
                                </Trigger>

<Trigger Property="IsChecked" Value="True">
       <Setter Property="ContentTemplate">
           <Setter.Value>
                  <DataTemplate>
                      <Image Source="{StaticResource Star}"/>
                  <DataTemplate>
           </Setter.Value>
       </Setter>
    <Setter Property="ToolTip" Value="{DynamicResource removeFromFavourite}"/>
</Trigger>

现在有效吗?