Example #1
0
 private static void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     SelectionChanged(sender, SelectedItemObserver.GetSelectedItem(sender));
 }
Example #2
0
        private static void PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (e.ClickCount > 1)
            {
                // If we get 2+ clicks, just ignore everything. In practice, this hasn't been hit.
                return;
            }
            var  control       = sender as ItemsControl;
            var  captured      = System.Windows.Input.Mouse.Captured as UIElement;
            bool isEditing     = GetIsEditing(control);
            var  inPlaceEditor = isEditing ? GetInPlaceEditor(control) : null;
            var  hitElement    = control.InputHitTest(e.GetPosition(control)) as UIElement;
            var  adorner       = (hitElement != null) ? hitElement.GetParent <System.Windows.Documents.Adorner>() : null;

            if (((captured != null) && (control != null) && !ReferenceEquals(captured, control)) || ((adorner != null) && (adorner == inPlaceEditor)))
            {
                return;
            }

            var clickedElement = e.OriginalSource as FrameworkElement;
            var listView       = clickedElement as ListView;

            if (listView != null)
            {
                clickedElement = listView.InputHitTest(e.GetPosition(listView)) as FrameworkElement;
            }
            bool clickedElementIsInPlaceEditor = (inPlaceEditor != null) && (clickedElement.GetParent <FrameworkElement>((v) => v is IInPlaceEditor) == inPlaceEditor);

            bool commit         = false;
            bool checkClickTime = true;

            Control clickedItem = clickedElement.GetParent <TreeViewItem>();

            if (clickedItem == null)
            {
                clickedItem = clickedElement.GetParent <ListViewItem>();
            }
            if (clickedItem == null && !clickedElementIsInPlaceEditor)
            {
                // Did not click on an item. Commit any in-progress edit, otherwise cancel.
                commit         = isEditing && (inPlaceEditor != null);
                checkClickTime = false;
            }

            var lastSelectedItem = GetLastSelectedItem(control);

            if (checkClickTime && ((lastSelectedItem == null) || (lastSelectedItem != SelectedItemObserver.GetSelectedItem(control))))
            {
                // Clicked on a different item. Commit the current edit if applicable.
                commit         = isEditing && (inPlaceEditor != null);
                checkClickTime = false;
                SetLastSelectedItem(control, null);
            }

            var lastClickedElement = GetLastClickedElement(control);

            if (checkClickTime && !clickedElementIsInPlaceEditor && ((lastClickedElement == null) || (lastClickedElement != clickedElement)))
            {
                SetLastClickedElement(control, clickedElement);
                SetLastSelectedTimestamp(control, e.Timestamp);
                checkClickTime = false;
            }

            if (checkClickTime)
            {
                var       lastSelectedTime = GetLastSelectedTimestamp(control);
                var       interval         = Math.Abs(e.Timestamp - lastSelectedTime);
                const int MinInterval      = 400;
                const int MaxInterval      = 1200;
                if (interval >= MinInterval && interval <= MaxInterval)
                {
                    SetIsEditing(control, true);
                }
                else if (interval <= System.Windows.Forms.SystemInformation.DoubleClickTime)
                {
                    SetLastSelectedTimestamp(control, 0); // ignore double+ clicks -- force restart of the check
                }
                else if (interval > MaxInterval)
                {
                    SetLastSelectedTimestamp(control, e.Timestamp);
                }
            }
            else if (commit)
            {
                inPlaceEditor.CommitEdit();
            }
        }
Example #3
0
 private static void TreeViewSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
 {
     SelectionChanged(sender, SelectedItemObserver.GetSelectedItem(sender));
 }