Reputation: 7419
i made check box in wpf ,Got it from Internet.I want to see which item is checked or unchecked.Any idea how to do this here goes the code
Class
public class CheckedListItem
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsChecked { get; set; }
public string Email { get; set; }
}
Usage
List<CheckedListItem> AvailablePresentationObjects = new List<CheckedListItem>();
CheckedListItem item = new CheckedListItem();
for (int i = 0; i < 10; i++)
{
item = new CheckedListItem();
item.Id = i;
item.Name = i.ToString();
item.IsChecked = false;
AvailablePresentationObjects.Add(item);
}
list.ItemsSource = AvailablePresentationObjects;
XMAL
<ListBox x:Name="list" Margin="3,277,0,0" Height="234" VerticalAlignment="Top" Selec
tionMode="Extended">
<ListBox.ItemTemplate>
<HierarchicalDataTemplate>
<my:RibbonCheckBox Label="{Binding Name}" IsChecked="{Binding IsChecked}" />
</HierarchicalDataTemplate>
</ListBox.ItemTemplate>
</ListBox>
took it from Here Checked ListBox
Question is
How to implement property change so that i can know which item was checked and which was unchecked
Upvotes: 2
Views: 446
Reputation: 7754
You can get collection of selected items: list.SelectedItems
.
Each item you can cast to CheckedListItem
and check that item is checked.
If you want to handle property changing, you should implement interface INotifyPropertyChanged
in CheckedListItem
class
Example of INotifyPropertyChanged:
Add this to your class and call OnPropertyChanged
in properties:
private boolean _isChecked;
public boolean IsChecked
{
get { return _isChecked; }
set
{
_isChecked= value;
OnPropertyChanged("IsChecked");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
Upvotes: 2