예제 #1
0
        /// <summary>
        /// Walk the visual tree to find the ItemsControl and
        /// hook into some of its events. This is done to make
        /// sure that editing is cancelled whenever
        ///
        ///   1> The parent control is scrolling its content
        /// 1.1> The MouseWheel is used
        ///   2> A user clicks outside the adorner control
        ///   3> The parent control changes its size
        ///
        /// </summary>
        private void HookItemsControlEvents()
        {
            if (_PART_MeasureTextBlock == null)
            {
                return;
            }

            _TextBox = new TextBox();

            _Adorner = new EditBoxAdorner(_PART_MeasureTextBlock, _TextBox, this);
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(_PART_MeasureTextBlock);

            if (layer == null) // This layer does not always seem to be available?
            {
                return;
            }

            layer.Add(_Adorner);

            // try to get the text box focused when layout finishes.
            _TextBox.LayoutUpdated += new EventHandler(this.OnTextBoxLayoutUpdated);

            CaptureMouse();
            Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnMouseDownOutsideElement);

            _TextBox.PreviewTextInput  += OnPreviewTextInput;
            _TextBox.KeyDown           += new KeyEventHandler(this.OnTextBoxKeyDown);
            _TextBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.OnTextBoxLostKeyboardFocus);

            _TextBox.LostFocus += new RoutedEventHandler(this.OnLostFocus);

            _ParentItemsControl = this.GetDpObjectFromVisualTree(this, typeof(ItemsControl)) as ItemsControl;
            Debug.Assert(_ParentItemsControl != null, "DEBUG ISSUE: No FolderTreeView found.");

            if (_ParentItemsControl != null)
            {
                // Handle events on parent control and determine whether to switch to Normal mode or stay in editing mode
                _ParentItemsControl.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(this.OnScrollViewerChanged));
                _ParentItemsControl.AddHandler(ScrollViewer.MouseWheelEvent, new RoutedEventHandler((s, e) => this.OnSwitchToNormalMode()), true);

                _ParentItemsControl.MouseDown   += new MouseButtonEventHandler((s, e) => this.OnSwitchToNormalMode());
                _ParentItemsControl.SizeChanged += new SizeChangedEventHandler((s, e) => this.OnSwitchToNormalMode());

                // Restrict text box to visible area of scrollviewer
                this.ParentScrollViewer = this.GetDpObjectFromVisualTree(_ParentItemsControl, typeof(ScrollViewer)) as ScrollViewer;

                if (this.ParentScrollViewer == null)
                {
                    this.ParentScrollViewer = FindVisualChild <ScrollViewer>(_ParentItemsControl);
                }

                Debug.Assert(this.ParentScrollViewer != null, "DEBUG ISSUE: No ScrollViewer found.");

                if (this.ParentScrollViewer != null)
                {
                    _TextBox.MaxWidth = this.ParentScrollViewer.ViewportWidth;
                }
            }
        }
예제 #2
0
        private void ProcessPanelType()
        {
            if (null == _ui_lbLeft || null == _ui_lbRight || null == _ui_tvLeft || null == _ui_tvRight)
            {
                return;
            }
            switch (ePanelType)
            {
            case PanelTypes.list:
                _ui_dlbLeft.Visibility = _ui_dlbRight.Visibility = Visibility.Visible;
                _ui_dtvLeft.Visibility = _ui_dtvRight.Visibility = Visibility.Collapsed;
                _ui_Search.DataContext = _ui_icLeft = _ui_lbLeft;
                _ui_icRight            = _ui_lbRight;
                break;

            case PanelTypes.tree:
                _ui_dlbLeft.Visibility = _ui_dlbRight.Visibility = Visibility.Collapsed;
                _ui_dtvLeft.Visibility = _ui_dtvRight.Visibility = Visibility.Visible;
                _ui_Search.DataContext = _ui_icLeft = _ui_tvLeft;
                _ui_icRight            = _ui_tvRight;
                break;
            }
            _ui_Search.DataContext = _ui_icLeft;
            if (null != _ui_icLeft)
            {
                _ui_icLeft.RemoveHandler(MouseLeftButtonDownEvent, (MouseButtonEventHandler)ItemsControl_MouseLeftButtonDown);
            }
            if (null != _ui_icRight)
            {
                _ui_icRight.RemoveHandler(MouseLeftButtonDownEvent, (MouseButtonEventHandler)ItemsControl_MouseLeftButtonDown);
            }
            _ui_icLeft.AddHandler(MouseLeftButtonDownEvent, (MouseButtonEventHandler)ItemsControl_MouseLeftButtonDown, true);
            _ui_icRight.AddHandler(MouseLeftButtonDownEvent, (MouseButtonEventHandler)ItemsControl_MouseLeftButtonDown, true);
            ProcessItemTemplate();
        }
        static GridViewSort()
        {
            PropertyChangedCallback commandCallback = (o, e) =>
            {
                ItemsControl listView = o as ItemsControl;
                if (listView != null)
                {
                    if (!GetAutoSort(listView))
                    {
                        if (e.OldValue != null && e.NewValue == null)
                        {
                            listView.RemoveHandler(ButtonBase.ClickEvent, new RoutedEventHandler(ColumnHeaderClick));
                        }

                        if (e.OldValue == null && e.NewValue != null)
                        {
                            listView.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(ColumnHeaderClick));
                        }
                    }
                }
            };

            CommandProperty = DependencyProperty.RegisterAttached(
                "Command",
                typeof(ICommand),
                typeof(GridViewSort),
                new UIPropertyMetadata(null, commandCallback));

            PropertyChangedCallback autoSortCallback = (o, e) =>
            {
                ListView listView = o as ListView;
                if (listView != null)
                {
                    // Don't change click handler if a command is set
                    if (GetCommand(listView) == null)
                    {
                        bool oldValue = (bool)e.OldValue;
                        bool newValue = (bool)e.NewValue;
                        if (oldValue && !newValue)
                        {
                            listView.RemoveHandler(ButtonBase.ClickEvent, new RoutedEventHandler(ColumnHeaderClick));
                        }

                        if (!oldValue && newValue)
                        {
                            listView.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(ColumnHeaderClick));
                        }
                    }
                }
            };

            AutoSortProperty = DependencyProperty.RegisterAttached(
                "AutoSort",
                typeof(bool),
                typeof(GridViewSort),
                new UIPropertyMetadata(false, autoSortCallback));
        }
예제 #4
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            PART_MonthLabel.MouseUp          += PartDateLabelOnMouseUp;
            PART_BackToDaySelectView.MouseUp += PartBackLabelOnMouseUp;

            PART_PreviousMonthButton.Click += previousMonthButtonClick;
            PART_NextMonthButton.Click     += nextMonthButtonClick;

            PART_CancelButton.Click += PartCancelButtonOnClick;

            PART_DayView.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(onCalendarDayButtonClick));
            PART_MonthView.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(onCalendarMonthButtonClick));
        }
예제 #5
0
        private static void OnCommandPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ItemsControl listView = o as ItemsControl;

            if (listView != null)
            {
                if (!GetAutoSort(listView))
                {
                    if (e.OldValue != null && e.NewValue == null)
                    {
                        listView.RemoveHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(ColumnHeader_Click));
                    }
                    if (e.OldValue == null && e.NewValue != null)
                    {
                        listView.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(ColumnHeader_Click));
                    }
                }
            }
        }
예제 #6
0
        private static void OnCommandPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            ItemsControl listView = obj as ItemsControl;

            if (listView != null)
            {
                if (!GetAutoSort(listView)) // Don't change click handler if AutoSort enabled
                {
                    if (args.OldValue != null && args.NewValue == null)
                    {
                        listView.RemoveHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(ColumnHeader_Click));
                    }
                    if (args.OldValue == null && args.NewValue != null)
                    {
                        listView.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(ColumnHeader_Click));
                    }
                }
            }
        }
예제 #7
0
        private static void OnCommandPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ItemsControl listView = sender as ItemsControl;

            if (listView != null)
            {
                if (!GetAutoSort(listView)) // Don't change click handler if AutoSort enabled
                {
                    if (e.OldValue != null && e.NewValue == null)
                    {
                        listView.RemoveHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnColumnHeaderClick));
                    }
                    if (e.OldValue == null && e.NewValue != null)
                    {
                        listView.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(OnColumnHeaderClick));
                    }
                }
            }
        }
        static void IsHandleSelectWithCtrlPropertyChangedCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            ItemsControl obj = target as ItemsControl;

            if (obj == null)
            {
                return;
            }

            var isHandle = (bool)e.NewValue;

            if (isHandle)
            {
                obj.AddHandler(UIElement.PreviewMouseDownEvent, PreviewMouseDownEventHandler, true);
            }
            else
            {
                obj.RemoveHandler(UIElement.PreviewMouseDownEvent, PreviewMouseDownEventHandler);
            }
        }
예제 #9
0
 static GridViewSort()
 {
     CommandProperty = DependencyProperty.RegisterAttached("Command", typeof(ICommand), typeof(GridViewSort), new UIPropertyMetadata(null, delegate(DependencyObject o, DependencyPropertyChangedEventArgs e) {
         ItemsControl control = o as ItemsControl;
         if ((control != null) && !GetAutoSort(control))
         {
             if ((e.OldValue != null) && (e.NewValue == null))
             {
                 control.RemoveHandler(ButtonBase.ClickEvent, new RoutedEventHandler(GridViewSort.ColumnHeader_Click));
             }
             if ((e.OldValue == null) && (e.NewValue != null))
             {
                 control.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(GridViewSort.ColumnHeader_Click));
             }
         }
     }));
     AutoSortProperty = DependencyProperty.RegisterAttached("AutoSort", typeof(bool), typeof(GridViewSort), new UIPropertyMetadata(false, delegate(DependencyObject o, DependencyPropertyChangedEventArgs e) {
         ListView view = o as ListView;
         if ((view != null) && (GetCommand(view) == null))
         {
             bool oldValue = (bool)e.OldValue;
             bool newValue = (bool)e.NewValue;
             if (oldValue && !newValue)
             {
                 view.RemoveHandler(ButtonBase.ClickEvent, new RoutedEventHandler(GridViewSort.ColumnHeader_Click));
             }
             if (!oldValue && newValue)
             {
                 view.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(GridViewSort.ColumnHeader_Click));
             }
         }
     }));
     PropertyNameProperty        = DependencyProperty.RegisterAttached("PropertyName", typeof(string), typeof(GridViewSort), new UIPropertyMetadata(null));
     ShowSortGlyphProperty       = DependencyProperty.RegisterAttached("ShowSortGlyph", typeof(bool), typeof(GridViewSort), new UIPropertyMetadata(true));
     SortGlyphAscendingProperty  = DependencyProperty.RegisterAttached("SortGlyphAscending", typeof(ImageSource), typeof(GridViewSort), new UIPropertyMetadata(null));
     SortGlyphDescendingProperty = DependencyProperty.RegisterAttached("SortGlyphDescending", typeof(ImageSource), typeof(GridViewSort), new UIPropertyMetadata(null));
     SortedColumnHeaderProperty  = DependencyProperty.RegisterAttached("SortedColumnHeader", typeof(GridViewColumnHeader), typeof(GridViewSort), new UIPropertyMetadata(null));
 }
예제 #10
0
        public override void OnApplyTemplate()
        {
            if (this._HomePageBtn != null)
            {
                _HomePageBtn.Click -= _HomePageBtn_Click;
            }

            if (this._PrePageButton != null)
            {
                _PrePageButton.Click -= _PrePageButton_Click;
            }

            if (_PageCenterItemsControl != null)
            {
                _PageCenterItemsControl.RemoveHandler(RadioButton.CheckedEvent, new RoutedEventHandler(RadioButtonChecked));
                _PageCenterItemsControl.Items.Clear();
            }

            if (this._NextPageButton != null)
            {
                this._NextPageButton.Click -= _NextPageButton_Click;
            }

            if (this._LastPageBtn != null)
            {
                this._LastPageBtn.Click -= _LastPageBtn_Click;
            }

            if (this._GoButtonBtn != null)
            {
                this._GoButtonBtn.Click -= _GoButtonBtn_Click;
            }

            if (this._GoTextBox != null)
            {
                this._GoTextBox.Text            = string.Empty;
                this._GoTextBox.PreviewKeyDown -= _GoTextBox_PreviewKeyDown;
            }

            base.OnApplyTemplate();
            this._HomePageBtn = (base.GetTemplateChild("PART_HomePage")) as Button;
            if (_HomePageBtn != null)
            {
                _HomePageBtn.Click += _HomePageBtn_Click;
            }

            this._PrePageButton = (base.GetTemplateChild("PART_PrePageButton")) as Button;
            if (this._PrePageButton != null)
            {
                _PrePageButton.Click += _PrePageButton_Click;
            }

            this._PageCenterItemsControl = (base.GetTemplateChild("PART_CenterPageItemsControl")) as ItemsControl;
            if (_PageCenterItemsControl != null)
            {
                _PageCenterItemsControl.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(RadioButtonChecked));
            }

            this._NextPageButton = (base.GetTemplateChild("PART_NextPageButton")) as Button;
            if (this._NextPageButton != null)
            {
                this._NextPageButton.Click += _NextPageButton_Click;
            }

            this._LastPageBtn = (base.GetTemplateChild("PART_LastPage")) as Button;
            if (this._LastPageBtn != null)
            {
                this._LastPageBtn.Click += _LastPageBtn_Click;
            }

            this._GoButtonBtn = (base.GetTemplateChild("PART_GoButton")) as Button;
            if (this._GoButtonBtn != null)
            {
                this._GoButtonBtn.Click += _GoButtonBtn_Click;
            }

            this._GoTextBox = (base.GetTemplateChild("PART_GoTextBox")) as TextBox;
            if (_GoTextBox != null)
            {
                this._GoTextBox.PreviewKeyDown += _GoTextBox_PreviewKeyDown;
            }

            Init();
        }