Mono exception to SocketException
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Core.Presentation / System / Activities / Core / Presentation / ReorderableListEditor.xaml.cs
1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //----------------------------------------------------------------
6
7 namespace System.Activities.Core.Presentation
8 {
9     using System.Activities.Presentation.Internal.PropertyEditing;
10     using System.Collections.ObjectModel;
11     using System.Windows;
12     using System.Windows.Controls;
13     using System.Windows.Input;
14
15     internal partial class ReorderableListEditor : UserControl
16     {
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));
20
21         public ReorderableListEditor()
22         {
23             this.InitializeComponent();
24         }
25         
26         public DataTemplate ItemTemplate
27         {
28             get { return (DataTemplate)this.GetValue(ItemTemplateProperty); }
29             set { this.SetValue(ItemTemplateProperty, value); }
30         }
31
32         public ObservableCollection<ExpandableItemWrapper> List
33         {
34             get { return (ObservableCollection<ExpandableItemWrapper>)this.GetValue(ListProperty); }
35             set { this.SetValue(ListProperty, value); }
36         }
37
38         public ExpandableItemWrapper SelectedListItem
39         {
40             get { return (ExpandableItemWrapper)this.GetValue(SelectedListItemProperty); }
41             set { this.SetValue(SelectedListItemProperty, value); }
42         }
43
44         protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
45         {
46             if (!this.listBox.IsKeyboardFocusWithin)
47             {
48                 this.listBox.UnselectAll();
49             }
50
51             base.OnIsKeyboardFocusWithinChanged(e);
52         }
53
54         private void OnListBoxPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
55         {
56             ListBoxItem item = VisualTreeUtils.FindVisualAncestor<ListBoxItem>(e.OriginalSource as DependencyObject);
57
58             if (item != null)
59             {
60                 this.SelectedListItem = item.Content as ExpandableItemWrapper;
61             }
62         }
63
64         private void OnUpArrowClicked(object sender, RoutedEventArgs e)
65         {
66             int oldIndex = this.List.IndexOf(this.SelectedListItem);
67             if (oldIndex > 0)
68             {
69                 this.List.Move(oldIndex, oldIndex - 1);
70             }
71         }
72
73         private void OnDownArrowClicked(object sender, RoutedEventArgs e)
74         {
75             int oldIndex = this.List.IndexOf(this.SelectedListItem);
76             if (oldIndex < this.List.Count - 1)
77             {
78                 this.List.Move(oldIndex, oldIndex + 1);
79             }
80         }
81     }
82 }