<ListView Grid.Row="1" Name="listbox" ItemsSource="{Binding Items}" Margin="5,5,5,5" Width="Auto" > <ListView.View > <GridView > <GridViewColumn Width="80" > <GridViewColumn.Header > <CheckBox x:Name="cbSelectAll" IsChecked="{Binding ModelDetails.IsChecked}" Command="{Binding cbSelectAll_Checked}"/> </GridViewColumn.Header> <GridViewColumn.CellTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <WrapPanel x:Name="Layout" > <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> </WrapPanel> </StackPanel> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </ListView.View > </GridView > </ListView>
class ViTypeModel : INotifyPropertyChanged { private bool _isSelected; private bool _isChecked; //Define an event based on delegates public event PropertyChangedEventHandler PropertyChanged; //Raise the event public void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { //publishing the event in current classs PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public bool IsChecked { get { return _isChecked; } set { _isChecked = value; OnPropertyChanged(nameof(IsChecked)); } } public bool IsSelected { get { return _isSelected; } set { _isSelected = value; OnPropertyChanged(nameof(IsSelected)); } }
private ViTypeModel _ModelDetails; public ViTypeModel ModelDetails { get { return _ModelDetails; } set { _ModelDetails = value; } }
public void SelectAllBtnExecute(object param) { foreach (var selectedItems in Items) { ModelDetails.IsSelected = ModelDetails.IsChecked; } }
INotifyPropertyChanged
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)