1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //----------------------------------------------------------------
7 namespace System.Activities.Core.Presentation
9 using System.Activities.Presentation.Internal.PropertyEditing;
10 using System.Collections.ObjectModel;
12 using System.Windows.Controls;
13 using System.Windows.Input;
15 internal partial class ReorderableListEditor : UserControl
17 public static readonly DependencyProperty ItemTemplateProperty = DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(ReorderableListEditor), new PropertyMetadata(null));
18 public static readonly DependencyProperty ListProperty = DependencyProperty.Register("List", typeof(ObservableCollection<ExpandableItemWrapper>), typeof(ReorderableListEditor), new PropertyMetadata(null));
19 public static readonly DependencyProperty SelectedListItemProperty = DependencyProperty.Register("SelectedListItem", typeof(ExpandableItemWrapper), typeof(ReorderableListEditor), new PropertyMetadata(null));
21 public ReorderableListEditor()
23 this.InitializeComponent();
26 public DataTemplate ItemTemplate
28 get { return (DataTemplate)this.GetValue(ItemTemplateProperty); }
29 set { this.SetValue(ItemTemplateProperty, value); }
32 public ObservableCollection<ExpandableItemWrapper> List
34 get { return (ObservableCollection<ExpandableItemWrapper>)this.GetValue(ListProperty); }
35 set { this.SetValue(ListProperty, value); }
38 public ExpandableItemWrapper SelectedListItem
40 get { return (ExpandableItemWrapper)this.GetValue(SelectedListItemProperty); }
41 set { this.SetValue(SelectedListItemProperty, value); }
44 protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
46 if (!this.listBox.IsKeyboardFocusWithin)
48 this.listBox.UnselectAll();
51 base.OnIsKeyboardFocusWithinChanged(e);
54 private void OnListBoxPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
56 ListBoxItem item = VisualTreeUtils.FindVisualAncestor<ListBoxItem>(e.OriginalSource as DependencyObject);
60 this.SelectedListItem = item.Content as ExpandableItemWrapper;
64 private void OnUpArrowClicked(object sender, RoutedEventArgs e)
66 int oldIndex = this.List.IndexOf(this.SelectedListItem);
69 this.List.Move(oldIndex, oldIndex - 1);
73 private void OnDownArrowClicked(object sender, RoutedEventArgs e)
75 int oldIndex = this.List.IndexOf(this.SelectedListItem);
76 if (oldIndex < this.List.Count - 1)
78 this.List.Move(oldIndex, oldIndex + 1);