Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ItemsControlVisibilityHelper : ContentControl
- {
- public static readonly DependencyProperty ItemsControlProperty =
- DependencyProperty.Register("ItemsControl",
- typeof (ItemsControl),
- typeof (ItemsControlVisibilityHelper),
- new PropertyMetadata(default(ItemsControl), OnItemsControlChanged));
- public ItemsControl ItemsControl
- {
- get { return (ItemsControl) GetValue(ItemsControlProperty); }
- set { SetValue(ItemsControlProperty, value); }
- }
- public static readonly DependencyProperty BoundItemProperty =
- DependencyProperty.Register("BoundItem",
- typeof (object),
- typeof (ItemsControlVisibilityHelper),
- new PropertyMetadata(default(object), OnBoundItemChanged));
- public object BoundItem
- {
- get { return GetValue(BoundItemProperty); }
- set { SetValue(BoundItemProperty, value); }
- }
- private static void OnItemsControlChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
- {
- var helper = obj as ItemsControlVisibilityHelper;
- helper.UpdateVisibility();
- }
- private static void OnBoundItemChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
- {
- var helper = obj as ItemsControlVisibilityHelper;
- helper.UpdateVisibility();
- }
- public void UpdateVisibility()
- {
- if(ItemsControl != null && BoundItem != null)
- {
- if(ItemsControl.ItemsSource is IList)
- {
- var collection = ItemsControl.ItemsSource as IList;
- var index = collection.IndexOf(BoundItem);
- if(index == collection.Count - 1)
- {
- Visibility = Visibility.Collapsed;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment