开发者

Checkbox in gridviewcolumn(header)

I am using a listview (gridview/gridviewcolumn) where the first column contains only checkboxes for each row. Instead of adding a select all button I want to add a Checkbox into the header of the first column.

Selecting the checkbox in the header will select all other checkboxes and vice versa.

How can I do that in xaml?

Update: This is the important part of my xaml code. (simplified)

<ListView ItemSource="...">
<ListView.View>
<GridView>

<GridViewColumn>
  <GridViewColumn.CellTemplate>
    <DataTemplate>
 开发者_如何学运维     <StackPanel Orientation="Horizontal">
         <CheckBox IsChecked="{Binding IsSelected}" />
      </StackPanel>
    </DataTemplate>
  </GridViewColumn.CellTemplate>
</GridViewColumn>

</GridView>
</ListView.View>
</ListView>


To have a checkbox on top of GridViewColumn you can do something like this

<GridViewColumn>

 <GridViewColumn.Header>
     <CheckBox/>
  </GridViewColumn.Header>

  <GridViewColumn.CellTemplate>
    <DataTemplate>
      <StackPanel Orientation="Horizontal">
         <CheckBox IsChecked="{Binding IsSelected}" />
      </StackPanel>
    </DataTemplate>
  </GridViewColumn.CellTemplate>
</GridViewColumn>

Now you can handle the check event and in the code you can iterate through your itemsSource and change values or if you are following MVVM you can bind property with checkbox so that whenever check is changed you will be notified through INotifyPropertyChanged. Once you find out through binding that check has changed, again you can change your itemssource accordingly

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜