예제 #1
0
 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));
 }
	    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();
		}
예제 #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.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);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Builds the visual tree for the DatePicker control when a new template is applied. 
        /// </summary>
        public override void OnApplyTemplate() {
            ReleaseCalendar();
            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 (_todayButton != null) {
                _todayButton.Click -= TodayButton_Click;
                BindingOperations.ClearAllBindings(_todayButton);
            }

            if (_clearButton != null) {
                _clearButton.Click -= ClearButton_Click;
                BindingOperations.ClearAllBindings(_clearButton);
            }

            if (_textBox != null) {
                FocusManager.SetIsFocusScope(_textBox, false);
                _textBox.Focusable = true;
                _textBox.RemoveHandler(KeyDownEvent, new KeyEventHandler(TextBox_KeyDown));
                _textBox.RemoveHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged));
                _textBox.RemoveHandler(LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
            }

            base.OnApplyTemplate();

            _calendar = GetTemplateChild(PartCalendarName) as Calendar;
            InitializeCalendar();

            _popUp = GetTemplateChild(PartPopupName) as Popup;

            if (_popUp != null) {
                _popUp.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                _popUp.Opened += PopUp_Opened;
                _popUp.Closed += PopUp_Closed;
                // While we have a calendar part in control's template ,this line is no longer necessary
                // _popUp.Child = _calendar;
                if (IsDropDownOpen)
                    _popUp.IsOpen = true;
            }

            _dropDownButton = GetTemplateChild(PartDropDownButtonName) 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 = "Select";
            }

            _todayButton = GetTemplateChild(PartTodayButtonName) as ButtonBase;
            if (_todayButton != null) {
                _todayButton.Click += TodayButton_Click;
                _todayButton.SetBinding(StyleProperty, GetSelfBinding(TodayButtonStyleProperty));
                SetTodayButtonContent();
            }

            _clearButton = GetTemplateChild(PartClearButtonName) as ButtonBase;
            if (_clearButton != null) {
                _clearButton.Click += ClearButton_Click;
                _clearButton.SetBinding(StyleProperty, GetSelfBinding(ClearButtonStyleProperty));
                _clearButton.SetBinding(ContentControl.ContentProperty, GetSelfBinding(ClearButtonContentProperty));
            }

            _textBox = GetTemplateChild(PartTextBoxName) as DatePickerTextBox;

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

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

                if (SelectedDate == null) {
                    if (!string.IsNullOrEmpty(_defaultText)) {
                        _textBox.Text = _defaultText;
                        SetSelectedDate();
                    }
                } else
                    _textBox.Text = DateTimeToString((DateTime)SelectedDate);
            }
            UpdateVisualState(true);
        }
예제 #5
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);
            }
        }