Exemple #1
0
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     _popupElement = GetTemplateChild(PopupElementName) as Popup;
     _popupElement.AddHandler(FrameworkElement.MouseLeftButtonUpEvent, new MouseButtonEventHandler(_popupElement_MouseLeftButtonUp), true);
     _scrollViewerElement = GetTemplateChild(ScrollViewerName) as ScrollViewer;
 }
        private void openMenu( )
        {
            if (expanded)
            {
                return;
            }

            if (this.Type == MenuItemType.Submenu || Type == MenuItemType.RootSubmenu)
            {
                if (null == popup)
                {
                    popup = new Popup(this.Items, this.popupShadow, this.ActualWidth);
                    foreach (MenuItemBase itemBase in this.Items)
                    {
                        if (itemBase is MenuItem)
                        {
                            (( MenuItem )itemBase).ParentItem = this;
                        }
                    }
                    popup.AddHandler(Window.ClosedEvent, new EventHandler(onPopupClosed));
                }
                WindowsHost windowsHost = VisualTreeHelper.FindClosestParent <WindowsHost>(this);
                Point       point       = TranslatePoint(this, new Point(0, 0), windowsHost);
                popup.X = point.X;
                popup.Y = point.Y;
                windowsHost.ShowModal(popup, true);
                expanded = true;
            }
        }
Exemple #3
0
        public override void OnApplyTemplate()
        {
            if (_popUp != null)//如果popup已经被赋值
            {
                //------------------路由事件--------------------------要移除的函数
                _popUp.RemoveHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
            }

            base.OnApplyTemplate();

            _popUp = GetTemplateChild("PART_Popup") as Popup;//获取前台的popup组件

            if (_popUp != null)
            {   //向 鼠标左键点击 路由事件(委托) 添加 执行函数 改变_disablePopupReopen
                _popUp.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                //当Popup的IsOpen属性为true时触发
                _popUp.Opened += PopUp_Opened;
                _popUp.Child   = _calendar;
            }

            _dropDownButton = GetTemplateChild("PART_Button") as Button;
            if (_dropDownButton != null)
            {
                _dropDownButton.Click += DropDownButton_Click;

                /*_dropDownButton.AddHandler(MouseLeaveEvent, new MouseEventHandler(DropDownButton_MouseLeave), true);
                 *
                 * // If the user does not provide a Content value in template, we provide a helper text that can be used in Accessibility
                 * // this text is not shown on the UI, just used for Accessibility purposes
                 * if (_dropDownButton.Content == null)
                 * {
                 *  _dropDownButton.Content = System.SR.Get(SRID.DatePicker_DropDownButtonName);
                 * }*/
            }
        }
 private static void Inititalize(Popup popup)
 {
     popup.StaysOpen = true;
     popup.Focusable = false;
     popup.ToolTip   = new ToolTip();
     (popup.ToolTip as ToolTip).Template = null;
     popup.AddHandler(RibbonControl.ClickEvent, new RoutedEventHandler(OnClick));
 }
Exemple #5
0
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     button        = (Button)Template.FindName("PART_Button", this);
     popup         = (Popup)Template.FindName("PART_Popup", this);
     button.Click += ButtonClick;
     popup.Opened += OnPopupOpened;
     popup.Closed += OnPopupClosed;
     popup.AddHandler(MouseUpEvent, new RoutedEventHandler(PopupMouseUp), true);
 }
Exemple #6
0
        public override void OnApplyTemplate()
        {
            if (_popup != null)
            {
                _popup.RemoveHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopupOnPreviewMouseLeftButtonDown));
                _popup.Opened -= PopupOnOpened;
                _popup.Closed -= PopupOnClosed;
                _popup.Child   = null;
            }
            if (_dropDownButton != null)
            {
                _dropDownButton.Click -= DropDownButtonOnClick;
            }
            if (_textBox != null)
            {
                _textBox.RemoveHandler(KeyDownEvent, new KeyEventHandler(TextBoxOnKeyDown));
                _textBox.RemoveHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(TextBoxOnTextChanged));
                _textBox.AddHandler(LostFocusEvent, new RoutedEventHandler(TextBoxOnLostFocus));
            }

            _textBox = GetTemplateChild(ElementTextBox) as TextBox;
            if (_textBox != null)
            {
                _textBox.AddHandler(KeyDownEvent, new KeyEventHandler(TextBoxOnKeyDown));
                _textBox.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(TextBoxOnTextChanged));
                _textBox.AddHandler(LostFocusEvent, new RoutedEventHandler(TextBoxOnLostFocus));
                _textBox.Text = Text;
            }

            _popup = GetTemplateChild(ElementPopup) as Popup;
            if (_popup != null)
            {
                _popup.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopupOnPreviewMouseLeftButtonDown));
                _popup.Opened += PopupOnOpened;
                _popup.Closed += PopupOnClosed;
                _popup.Child   = _clockHostContentControl;
                if (IsDropDownOpen)
                {
                    _popup.IsOpen = true;
                }
            }

            _dropDownButton = GetTemplateChild(ElementButton) as Button;
            if (_dropDownButton != null)
            {
                _dropDownButton.Click += DropDownButtonOnClick;
            }

            base.OnApplyTemplate();
        }
        bool RenderCore()
        {
            if (session.IsDismissed || session.HexView.IsClosed)
            {
                return(false);
            }
            if (wpfHexView is null)
            {
                return(false);
            }

            var point = session.TriggerPoint;

            Debug.Assert(!point.IsDefault);
            if (point.IsDefault)
            {
                return(false);
            }

            var line = session.HexView.HexViewLines.GetHexViewLineContainingBufferPosition(point.BufferPosition);

            Debug2.Assert(line is not null && line.VisibilityState != VSTF.VisibilityState.Unattached);
            if (line is null || line.VisibilityState == VSTF.VisibilityState.Unattached)
            {
                return(false);
            }

            var linePosition = line.BufferLine.GetLinePosition(point) ?? 0;
            var bounds       = line.GetExtendedCharacterBounds(linePosition);

            popup.HorizontalOffset = bounds.Left - wpfHexView.ViewportLeft;
            popup.VerticalOffset   = bounds.TextBottom - session.HexView.ViewportTop;

            HexPopupHelper.SetScaleTransform(wpfHexView, popup);
            popup.Child      = control;
            popup.Visibility = Visibility.Visible;
            popup.IsOpen     = true;

            wpfHexView.VisualElement.MouseLeave += VisualElement_MouseLeave;
            wpfHexView.VisualElement.MouseMove  += VisualElement_MouseMove;
            popup.AddHandler(UIElement.MouseLeaveEvent, new MouseEventHandler(Popup_MouseLeave), handledEventsToo: true);
            wpfHexView.Caret.PositionChanged += Caret_PositionChanged;
            wpfHexView.LayoutChanged         += HexView_LayoutChanged;
            return(true);
        }
Exemple #8
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            var popup = Template.FindName("PART_Popup", this);

            if (popup is Popup)
            {
                _popup   = (Popup)this.Template.FindName("PART_Popup", this);
                _content = (ContentPresenter)this.Template.FindName("PART_Content", this);

                _popup.AddHandler(Popup.LostFocusEvent,
                                  new RoutedEventHandler((o, e) =>
                {
                    //(o as DropDownControl).
                    //IsDropDownOpen = false;
                }));
            }
        }
Exemple #9
0
        /// <summary>
        /// Builds the visual tree for the DatePicker control when a new template is applied.
        /// </summary>
        public override void OnApplyTemplate()
        {
            if (_popUp != null)
            {
                _popUp.RemoveHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popUp.Opened -= PopUp_Opened;
                _popUp.Closed -= PopUp_Closed;
                _popUp.Child   = null;
            }

            if (_dropDownButton != null)
            {
                _dropDownButton.Click -= DropDownButton_Click;
                _dropDownButton.RemoveHandler(MouseLeaveEvent, new MouseEventHandler(DropDownButton_MouseLeave));
            }

            if (_textBox != null)
            {
                _textBox.RemoveHandler(TextBox.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown));
                _textBox.RemoveHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged));
                _textBox.RemoveHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
            }

            base.OnApplyTemplate();

            _popUp = GetTemplateChild(ElementPopup) as Popup;

            if (_popUp != null)
            {
                _popUp.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popUp.Opened += PopUp_Opened;
                _popUp.Closed += PopUp_Closed;
                _popUp.Child   = this._calendar;

                if (this.IsDropDownOpen)
                {
                    this._popUp.IsOpen = true;
                }
            }

            _dropDownButton = GetTemplateChild(ElementButton) as Button;
            if (_dropDownButton != null)
            {
                _dropDownButton.Click += DropDownButton_Click;
                _dropDownButton.AddHandler(MouseLeaveEvent, new MouseEventHandler(DropDownButton_MouseLeave), true);

                // If the user does not provide a Content value in template, we provide a helper text that can be used in Accessibility
                // this text is not shown on the UI, just used for Accessibility purposes
                if (_dropDownButton.Content == null)
                {
                    _dropDownButton.Content = SR.Get(SRID.DatePicker_DropDownButtonName);
                }
            }

            _textBox = GetTemplateChild(ElementTextBox) as DatePickerTextBox;

            if (this.SelectedDate == null)
            {
                SetWaterMarkText();
            }

            if (_textBox != null)
            {
                _textBox.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown), true);
                _textBox.AddHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged), true);
                _textBox.AddHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus), true);

                if (this.SelectedDate == null)
                {
                    if (!string.IsNullOrEmpty(this._defaultText))
                    {
                        _textBox.Text = this._defaultText;
                        SetSelectedDate();
                    }
                }
                else
                {
                    _textBox.Text = this.DateTimeToString((DateTime)this.SelectedDate);
                }
            }
        }
Exemple #10
0
        private void openMenu( ) {
            if ( expanded ) return;

            if ( this.Type == MenuItemType.Submenu || Type == MenuItemType.RootSubmenu ) {
                if (null == popup) {
                    popup = new Popup(this.Items, this.popupShadow, this.ActualWidth);
                    foreach ( MenuItemBase itemBase in this.Items ) {
                        if ( itemBase is MenuItem )
                            ( ( MenuItem ) itemBase ).ParentItem = this;
                    }
                    popup.AddHandler(Window.ClosedEvent, new EventHandler(onPopupClosed));
                }
                WindowsHost windowsHost = VisualTreeHelper.FindClosestParent<WindowsHost>(this);
                Point point = TranslatePoint(this, new Point(0, 0), windowsHost);
                popup.X = point.X;
                popup.Y = point.Y;
                windowsHost.ShowModal(popup, true);
                expanded = true;
            }
        }
Exemple #11
0
        /// <summary>
        /// Builds the visual tree for the DatePicker control when a new template is applied.
        /// </summary>
        public override void OnApplyTemplate()
        {
            if (_popUp != null)
            {
                _popUp.RemoveHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popUp.Opened -= PopUp_Opened;
                _popUp.Closed -= PopUp_Closed;
                _popUp.Child   = null;
            }

            if (_dropDownButton != null)
            {
                _dropDownButton.Click -= DropDownButton_Click;
                _dropDownButton.RemoveHandler(MouseLeaveEvent, new MouseEventHandler(DropDownButton_MouseLeave));
            }

            if (_textBox != null)
            {
                _textBox.RemoveHandler(TextBox.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown));
                _textBox.RemoveHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged));
                _textBox.RemoveHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
            }

            base.OnApplyTemplate();

            _popUp = GetTemplateChild(ElementPopup) as Popup;

            if (_popUp != null)
            {
                _popUp.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popUp.Opened += PopUp_Opened;
                _popUp.Closed += PopUp_Closed;
                _popUp.Child   = this._calendar;


                if (this.IsDropDownOpen)
                {
                    this._popUp.IsOpen = true;
                }
            }

            _dropDownButton = GetTemplateChild(ElementButton) as Button;
            if (_dropDownButton != null)
            {
                _dropDownButton.Click += DropDownButton_Click;
                _dropDownButton.AddHandler(MouseLeaveEvent, new MouseEventHandler(DropDownButton_MouseLeave), true);

                // If the user does not provide a Content value in template, we provide a helper text that can be used in Accessibility
                // this text is not shown on the UI, just used for Accessibility purposes
                if (_dropDownButton.Content == null)
                {
                    _dropDownButton.Content = SR.Get(SRID.DatePicker_DropDownButtonName);
                }
            }

            _textBox = GetTemplateChild(ElementTextBox) as DatePickerTextBox;

            UpdateDisabledVisual();
            if (this.SelectedDate == null)
            {
                SetWaterMarkText();
            }

            if (_textBox != null)
            {
                _textBox.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown), true);
                _textBox.AddHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged), true);
                _textBox.AddHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus), true);

                if (this.SelectedDate == null)
                {
                    if (!string.IsNullOrEmpty(this._defaultText))
                    {
                        _textBox.Text = this._defaultText;
                        SetSelectedDate();
                    }
                }
                else
                {
                    _textBox.Text = this.DateTimeToString((DateTime)this.SelectedDate);
                }
            }

            if (IsButtonDynamicShow)
            {
                _dropDownButton.Visibility = System.Windows.Visibility.Collapsed;
                Grid oGrid = GetTemplateChild("PART_Root") as Grid;
                oGrid.MouseEnter += new MouseEventHandler(_popUp_MouseEnter);
                oGrid.MouseLeave += new MouseEventHandler(_popUp_MouseLeave);
            }
            if (HideTextBoxBackground)
            {
                _textBox.Watermark       = string.Empty;
                _textBox.BorderBrush     = null;
                _textBox.BorderThickness = new Thickness(0);
                _textBox.Background      = null;
                this.BorderThickness     = new Thickness(0);
            }
        }
        public override void OnApplyTemplate()
        {
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            if (_dropDownButton != null)
            {
                _dropDownButton.Click -= DropDownButton_Click;
            }
            if (_setButton != null)
            {
                _setButton.Click -= SetButton_Click;
            }

            base.OnApplyTemplate();

            _rootPanel       = GetTemplateChild(ElementRootPanel) as DockPanel;
            _dropDownButton  = GetTemplateChild(ElementDropDownButton) as ToggleButton;
            _setButton       = GetTemplateChild(ElementSetButton) as Button;
            _popup           = GetTemplateChild(ElementPopup) as Popup;
            _startDatePicker = GetTemplateChild(ElementStartDatePicker) as DatePicker;
            _endDatePicker   = GetTemplateChild(ElementEndDatePicker) as DatePicker;
            if (_rootPanel == null || _dropDownButton == null || _setButton == null || _popup == null || _startDatePicker == null || _endDatePicker == null)
            {
                throw new InvalidOperationException(string.Format("You have missed to specify {0}, {1}, {2}, {3}, {4}, {5} in your template",
                                                                  ElementRootPanel, ElementDropDownButton, ElementSetButton, ElementPopup, ElementStartDatePicker, ElementEndDatePicker));
            }
            _rootPanel.ContextMenu = new ContextMenu();
            _rootPanel.ContextMenu.Items.Add(new MenuItem {
                Header = "Сегодня", Tag = "today"
            });
            _rootPanel.ContextMenu.Items.Add(new MenuItem {
                Header = "Вчера", Tag = "yesterday"
            });
            _rootPanel.ContextMenu.Items.Add(new MenuItem {
                Header = "Текущая неделя", Tag = "this week"
            });
            _rootPanel.ContextMenu.Items.Add(new MenuItem {
                Header = "Предыдущая неделя", Tag = "prev week"
            });
            _rootPanel.ContextMenu.Items.Add(new MenuItem {
                Header = "Предыдущая и текущая неделя", Tag = "prev and this week"
            });
            _rootPanel.ContextMenu.Items.Add(new MenuItem {
                Header = "Текущий месяц", Tag = "this month"
            });
            _rootPanel.ContextMenu.Items.Add(new MenuItem {
                Header = "Предыдущий месяц", Tag = "prev month"
            });
            _rootPanel.ContextMenu.Items.Add(new MenuItem {
                Header = "Предыдущий и текущий месяц", Tag = "prev and this month"
            });
            foreach (MenuItem item in _rootPanel.ContextMenu.Items)
            {
                item.Click += ContextMenuItem_Click;
            }

            if (_dropDownButton != null)
            {
                _dropDownButton.Click += DropDownButton_Click;
            }
            if (_setButton != null)
            {
                _setButton.Click += SetButton_Click;
            }
            if (_popup != null)
            {
                _popup.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popup.Opened += _PopUp_Opened;
            }
        }