protected override void Invoke(object parameter) { if (IsChecked) { if (EnableSelectedCache) { ItemsSelected(TargetElement.Items, true); foreach (var item in TargetElement.SelectedItems) { _cache.Add(item); } TargetElement.SetValue(CacheSelectedItemsProperty, _cache.ToList()); } else { TargetElement.SelectAll(); } } else { TargetElement.UnselectAll(); if (EnableSelectedCache) { foreach (var item in TargetElement.Items) { _cache.Remove(item); } ItemsSelected(TargetElement.Items, false); TargetElement.SetValue(CacheSelectedItemsProperty, _cache.ToList()); } else { TargetElement.UnselectAll(); } } AssociatedObject.SetValue(SelectedItemsCountProperty, _cache.Count); }