Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<MyObject> _localCollection = new List<MyObject>();
- List<MyObject> LocalCollection
- {
- get { return _localCollection; }
- set
- {
- _localCollection = value;
- OnPropertyChanged("LocalCollection");
- }
- }
- <GridView Name="grdItems">
- <GridViewColumn>
- <GridViewColumn.Header>
- <CheckBox/>
- </GridViewColumn.Header>
- <!--Column Template-->
- <GridViewColumn.CellTemplate>
- <DataTemplate>
- <StackPanel Orientation="Horizontal">
- <CheckBox Tag="{Binding ObjID}"
- IsChecked="{Binding ToRemove, Mode=OneWay}"
- Checked="SelectRelative" />
- </StackPanel>
- </DataTemplate>
- </GridViewColumn.CellTemplate>
- </GridViewColumn>
- private void SelectRelative(object sender, RoutedEventArgs e)
- {
- Dispatcher.BeginInvoke((Action)(() =>
- {
- //Get the Object Id we need
- int selectedId = Convert.ToInt32(((CheckBox)sender).Tag);
- //Get all objects that share this ID
- List<MyObjects> objLst = new List<MyObjects>(((IEnumerable<MyObjects>)grdItems.ItemsSource));
- //Clear the local collection property of our items used in the items source
- LocalCollection.Clear();
- //Remove the items source since we are updating it
- grdItems.ItemsSource = null;
- //Go through each item in the list and if the object id's match select them to remove
- foreach(var item in objLst)
- {
- if(item.ObjId == selectedId)
- item.ToRemove = true;
- //Add the object to our property
- LocalCollection.Add(item);
- }
- //Re-establish the item source with our new collection
- grdItems.ItemsSource = LocalCollection;
- }));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement