示例#1
0
        private void RegisterSetPasswordScope()
        {
            _revealButton = this.GetTemplateChild(RevealButtonPartName) as ButtonBase;

            if (_revealButton != null)
            {
                var beginReveal = new PointerEventHandler(BeginReveal);
                var endReveal   = new PointerEventHandler(EndReveal);

                // Button will handle Pressed and Released, so we have subscribe to handled events too
                _revealButton.AddHandler(PointerPressedEvent, beginReveal, handledEventsToo: true);
                _revealButton.AddHandler(PointerReleasedEvent, endReveal, handledEventsToo: true);
                _revealButton.AddHandler(PointerExitedEvent, endReveal, handledEventsToo: true);
                _revealButton.AddHandler(PointerCanceledEvent, endReveal, handledEventsToo: true);
                _revealButton.AddHandler(PointerCaptureLostEvent, endReveal, handledEventsToo: true);

                _revealButtonSubscription.Disposable = Disposable.Create(() =>
                {
                    _revealButton.RemoveHandler(PointerPressedEvent, beginReveal);
                    _revealButton.RemoveHandler(PointerReleasedEvent, endReveal);
                    _revealButton.RemoveHandler(PointerExitedEvent, endReveal);
                    _revealButton.RemoveHandler(PointerCanceledEvent, endReveal);
                    _revealButton.RemoveHandler(PointerCaptureLostEvent, endReveal);
                });
            }

            CheckRevealModeForScope();
        }
示例#2
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);
                }
            }
        }
示例#3
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.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.PreviewTextInput -= TextBox_PreviewTextInput;
                textBox.TextChanged      -= TextBox_TextChanged;
            }

            base.OnApplyTemplate();

            popup = GetTemplateChild(ElementPopup) as Popup;

            if (popup != null)
            {
                popup.Opened += popup_Opened;
                popup.Closed += popup_Closed;

                var visualParent = VisualTreeHelper.GetParent(PopupView);
                if (visualParent != null)
                {
                    var deco = visualParent as Decorator;
                    if (deco != null)
                    {
                        deco.Child = null;
                    }
                }

                var logicalParent = PopupView.Parent;
                if (logicalParent != null)
                {
                    var p = PopupView.Parent as Popup;
                    if (p != null)
                    {
                        p.Child = null;
                    }
                }

                popup.Child = PopupView;
            }

            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 = "...";
                }
            }

            textBox = GetTemplateChild(ElementTextBox) as TextBox;
            if (textBox != null)
            {
                textBox.PreviewTextInput += TextBox_PreviewTextInput;
                textBox.TextChanged      += TextBox_TextChanged;
            }
        }
示例#4
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);
            }
        }