I have a list view which contains checkboxes. How I can get if it is checked or not?
XAML:
<ListView Name="listview1" ItemsSource="{Binding UserCollection}">
<ListView.View>
<GridView>
<GridViewColumn Header="Discription" Width="170">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Discription}" Width="Auto"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Value" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<CheckBox IsChecked="{Binding Path=Value}" Content="{Binding Path=Value}" Width="70" Name="ckBox1"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
OR does it possible when user unchecks or checks checkboxes ‘Value’ in collection changed?
ObservableCollection<UserData> _UserCollection = new ObservableCollection<UserData>();
public ObservableCollection<UserData> UserCollection
{
get { return _UserCollection; }
}
public class UserData
{
public string Discription { get; set; }
public bool Value { get; set; }
}
ObservableCollection simply raises events when the contents of the collection change, not when a property of one of your UserData classes change. You may want to consider making UserData implement INotifyPropertyChanged. This way you can programaticaly set the Value property and the UI bound checkbox will automatically be checked/unchecked appropriately.