Exemple #1
0
		static public void ReadOnlyProperties (ButtonBase bb)
		{
			Assert.IsFalse ((bool) bb.GetValue (ButtonBase.IsFocusedProperty), "Get/IsFocusedProperty");
			Assert.IsFalse ((bool) bb.GetValue (ButtonBase.IsMouseOverProperty), "Get/IsMouseOverProperty");
			Assert.IsFalse ((bool) bb.GetValue (ButtonBase.IsPressedProperty), "Get/IsPressedProperty");

			Assert.Throws<InvalidOperationException> (delegate {
				bb.SetValue (ButtonBase.IsFocusedProperty, true);
			});
			Assert.IsFalse (bb.IsFocused, "IsFocused");

			Assert.Throws<InvalidOperationException> (delegate {
				bb.SetValue (ButtonBase.IsMouseOverProperty, true);
			});
			Assert.IsFalse (bb.IsMouseOver, "IsMouseOver");

			Assert.Throws<InvalidOperationException> (delegate {
				bb.SetValue (ButtonBase.IsPressedProperty, true);
			});
			Assert.IsFalse (bb.IsPressed, "IsPressed");

			bb.ClearValue (ButtonBase.IsFocusedProperty);
			bb.ClearValue (ButtonBase.IsMouseOverProperty);
			bb.ClearValue (ButtonBase.IsPressedProperty);
		}
		protected ButtonBaseAutomationPeer (ButtonBase owner)
			: base (owner)
		{
			textBlock = owner.Content as TextBlock;
			if (textBlock != null)
				textBlock.UIATextChanged += TextBlock_TextChanged;
		}
Exemple #3
0
        protected ButtonBackend(ButtonBase impl)
        {
            if (impl == null)
                throw new ArgumentNullException ("impl");

            Widget = impl;
        }
 /// <summary>
 /// Gets the value of the ConfigData attached property for a specified ButtonBase.
 /// </summary>
 /// <param name="element">The ButtonBase from which the property value is read.</param>
 /// <returns>The ConfigData property value for the ButtonBase.</returns>
 public static string GetConfigData(ButtonBase element)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     return element.GetValue(ConfigDataProperty) as string;
 }
        internal void AddButtonToMap(ButtonBase btn, ICommand cmd)
        {
            if (!ContainsCommand(cmd))
                _map.Add(new WeakReference(cmd), new List<WeakReference>());

            List<WeakReference> weakRefs = GetButtonsFromCommand(cmd);
            weakRefs.Add(new WeakReference(btn));
        }
 /// <summary>
 /// Sets the value of the ConfigData attached property to a specified ButtonBase.
 /// </summary>
 /// <param name="element">The ButtonBase to which the attached property is written.</param>
 /// <param name="value">The needed ConfigData value.</param>
 public static void SetConfigData(ButtonBase element, string value)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     element.SetValue(ConfigDataProperty, value);
 }
        internal void AddButtonToMap(ButtonBase button, ICommand comand)
        {
            if (!ContainsCommand(comand))
            {
                _map.Add(new WeakReference(comand), new List<WeakReference>());
            }

            var weakRefs = GetButtonsFromCommand(comand);
            weakRefs.Add(new WeakReference(button));
        }
 private static ButtonBaseClickCommandBehavior GetOrCreateBehavior(ButtonBase buttonBase)
 {
     var behavior = buttonBase.GetValue(clickCommandBehaviorProperty) as ButtonBaseClickCommandBehavior;
     if (behavior == null)
     {
         behavior = new ButtonBaseClickCommandBehavior(buttonBase);
         buttonBase.SetValue(clickCommandBehaviorProperty, behavior);
     }
     return behavior;
 }
Exemple #9
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _textBox = GetTemplateChild(PART_TextBox) as TextBox;
            _button = GetTemplateChild(PART_ButtonBase) as ButtonBase;

            if (_button != null)
            {
                _button.Click += ButtonClick;
            }
        }
        public override void OnApplyTemplate()
        {
            // Close Button
            ButtonBase oldCloseButton = _partCloseButton;
            _partCloseButton = Template.FindName("PART_CloseButton", this) as ButtonBase;

            if (!ReferenceEquals(oldCloseButton, _partCloseButton))
            {
                if (oldCloseButton != null)
                {
                    oldCloseButton.Click -= OnCloseButtonClick;
                }

                if (_partCloseButton != null)
                {
                    _partCloseButton.Click += OnCloseButtonClick;
                }
            }

            // Minimize Button
            ButtonBase oldMinimizeButton = _partMinimizeButton;
            _partMinimizeButton = Template.FindName("PART_MinimizeButton", this) as ButtonBase;

            if (!ReferenceEquals(oldMinimizeButton, _partMinimizeButton))
            {
                if (oldMinimizeButton != null)
                {
                    oldMinimizeButton.Click -= OnMinimizeButtonClick;
                }

                if (_partMinimizeButton != null)
                {
                    _partMinimizeButton.Click += OnMinimizeButtonClick;
                }
            }

            // Maximize Button
            ButtonBase oldMaximizeButton = _partMaximizeButton;
            _partMaximizeButton = Template.FindName("PART_MaximizeButton", this) as ButtonBase;

            if (!ReferenceEquals(oldMaximizeButton, _partMaximizeButton))
            {
                if (oldMaximizeButton != null)
                {
                    oldMaximizeButton.Click -= OnMaximizeButtonClick;
                }

                if (_partMaximizeButton != null)
                {
                    _partMaximizeButton.Click += OnMaximizeButtonClick;
                }
            }
        }
            public ButtonEventCheck(ButtonBase ButtonBase, bool showMessageBoxFlg)
            {
                RoutedEventHandler handler = (s, e) =>
                {
                    ButtonClickCalled = true;
                    if (showMessageBoxFlg)
                    {
                        MessageBox.Show("TestMessageWindow");
                    }
                };

                ButtonBase.Click += handler;
            }
Exemple #12
0
        /// <summary>
        /// Gets the action associated with the specified Button.
        /// </summary>
        /// <param name="button">The Button to lookup.</param>
        /// <returns>The action associated with the Button; null if there is none.</returns>
        public static TriggerAction GetAction(ButtonBase button)
        {
            TriggerCollection triggers = (TriggerCollection)button.GetValue(TriggersProperty);
            if (triggers != null) {
                foreach (Trigger trigger in triggers) {
                    ClickTrigger clickTrigger = trigger as ClickTrigger;
                    if (clickTrigger != null) {
                        return clickTrigger.Action;
                    }
                }
            }

            return null;
        }
        internal void RemoveButtonFromMap(ButtonBase btn, ICommand cmd)
        {
            List<WeakReference> buttonRefs = this.GetButtonsFromCommand(cmd);
            if (buttonRefs == null)
                return;

            for (int i = buttonRefs.Count - 1; i > -1; --i)
            {
                WeakReference weakRef = buttonRefs[i];
                if (weakRef.Target == btn)
                {
                    buttonRefs.RemoveAt(i);
                    break;
                }
            }
        }
Exemple #14
0
        //--------------------------------------------------------------
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or internal
        /// processes call <see cref="FrameworkElement.ApplyTemplate"/>.
        /// </summary>
        public override void OnApplyTemplate()
        {
            // Clean up.
            if (_button != null)
            {
                _button.Click -= OnButtonClick;
                _button = null;
            }

            base.OnApplyTemplate();

            // Find new button and install event handler.
            _button = GetTemplateChild("PART_Button") as ButtonBase;
            if (_button != null)
            {
                _button.Click += OnButtonClick;
            }
        }
        internal void RemoveButtonFromMap(ButtonBase button, ICommand command)
        {
            var buttonRefs = GetButtonsFromCommand(command);
            if (buttonRefs == null)
            {
                return;
            }

            for (var i = buttonRefs.Count - 1; i > -1; --i)
            {
                var weakRef = buttonRefs[i];
                if (weakRef.Target == button)
                {
                    buttonRefs.RemoveAt(i);
                    break;
                }
            }
        }
Exemple #16
0
        /// <summary>
        /// <InheriteDoc/>
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.Button = GetTemplateChild(PART_DropDownButton) as ToggleButton;

            this.mContentPresenter = GetTemplateChild(PART_ContentPresenter) as ContentPresenter;

            if (this.mPopup != null)
            {
                this.mPopup.Opened -= this.Popup_Opened;
            }

            this.mPopup = GetTemplateChild(PART_Popup) as Popup;

            if (this.mPopup != null)
            {
                this.mPopup.Opened += this.Popup_Opened;
            }
        }
Exemple #17
0
        /// <summary>
        /// <InheriteDoc/>
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.Button = GetTemplateChild(PART_DropDownButton) as ToggleButton;

            this.mItemsControl = GetTemplateChild(PART_ItemsControl) as ItemsControl;

            if (this.mPopup != null)
            {
                this.mPopup.Opened -= this.Popup_Opened;
            }

            this.mPopup = GetTemplateChild(PART_Popup) as Popup;

            if (this.mPopup != null)
            {
                this.mPopup.Opened += this.Popup_Opened;
            }
        }
Exemple #18
0
 public void OnTargetButtonChanged(ButtonBase button)
 {
     if (button != null)
     {
         button.Click += (s, e) => { this.IsOpen = true; };
         //UserControl window = TreeHelper.TryFindParent<UserControl>(button);
         //if (window == null)
         //{
         //    return;
         //}
         //window.PreviewMouseLeftButtonDown += (s, e) =>
         //{
         //    if (this.IsOpen && !this.IsMouseOver)
         //    {
         //        e.Handled = true;
         //        this.IsOpen = false;
         //    }
         //};
     }
 }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            FirstButton = (ButtonBase)GetTemplateChild("FirstButton");
            PreviousButton = (ButtonBase)GetTemplateChild("PreviousButton");
            NextButton = (ButtonBase)GetTemplateChild("NextButton");
            LastButton = (ButtonBase)GetTemplateChild("LastButton");
            AddButton = (ButtonBase)GetTemplateChild("AddButton");
            DeleteButton = (ButtonBase)GetTemplateChild("DeleteButton");
            CurrentPositionTextBox = (TextBox)GetTemplateChild("CurrentPositionTextBox");
            ItemCountTextBlock = (TextBlock)GetTemplateChild("ItemCountTextBlock");

            // ReSharper disable PossibleNullReferenceException
            FirstButton.Click += delegate { CurrentPosition = 1; };
            PreviousButton.Click += delegate { CurrentPosition--; };
            NextButton.Click += delegate { CurrentPosition++; };
            LastButton.Click += delegate { CurrentPosition = ItemsSource.Count; };
            DeleteButton.Click += DeleteButton_Click;
            AddButton.Click += AddButton_Click;
            // ReSharper restore PossibleNullReferenceException
        }
 private void ToggleLanguagePopup(ButtonBase button)
 {
     _langPopup.PlacementTarget = button;
     _langPopup.Placement = PlacementMode.Custom;
     _langPopup.CustomPopupPlacementCallback = (size, targetSize, offset) =>
     {
         var placement1 =
             new CustomPopupPlacement(new Point(0 - (size.Width - targetSize.Width), (0 - size.Height) - 5),
                 PopupPrimaryAxis.Horizontal);
         return new[] {placement1, placement1};
     };
     _langPopup.IsOpen = true;
 }
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application 
        /// code or internal processes (such as a rebuilding layout pass) call 
        /// ApplyTemplate. In simplest terms, this means the method is called 
        /// just before a UI element displays in an application.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // get template items
            moveFirstButton = GetTemplateChild("MoveFirstButton") as ButtonBase;
            movePreviousButton = GetTemplateChild("MovePreviousButton") as ButtonBase;
            currentRecordNumberTextBox = GetTemplateChild("CurrentRecordNumberTextBox") as TextBox;
            moveNextButton = GetTemplateChild("MoveNextButton") as ButtonBase;
            moveLastButton = GetTemplateChild("MoveLastButton") as ButtonBase;
            numberOfRecordsTextBlock = GetTemplateChild("NumberOfRecordsTextBlock") as TextBlock;
            optionsButton = GetTemplateChild("OptionsButton") as ButtonBase;
            popupMenu = GetTemplateChild("PopupMenu") as Popup;
            clearSelectionMenuButton = GetTemplateChild("ClearSelectionMenuButton") as ButtonBase;
            switchSelectionMenuButton = GetTemplateChild("SwitchSelectionMenuButton") as ButtonBase;
            selectAllMenuButton = GetTemplateChild("SelectAllMenuButton") as ButtonBase;
            zoomToSelectionMenuButton = GetTemplateChild("ZoomToSelectionMenuButton") as ButtonBase;
            deleteSelectedRowsMenuButton = GetTemplateChild("DeleteSelectedRowsMenuButton") as ButtonBase;
            submitChangesMenuButton = GetTemplateChild("SubmitChangesMenuButton") as ButtonBase;
            autoChangeMapExtentCheckBox = GetTemplateChild("AutoChangeMapExtentCheckBox") as ToggleButton;

            #if SILVERLIGHT
            rowsPresenter = GetTemplateChild("RowsPresenter") as DataGridRowsPresenter;
            #endif
            // Add event handlers for status bar
            InitializeFeatureDataGrid();
        }
Exemple #22
0
        /// <summary>
        /// Sets the name of the command associated with the specified Button.
        /// </summary>
        /// <param name="button">The Button to associate the command with.</param>
        /// <param name="commandName">The name of the command to associated.</param>
        public static void SetCommand(ButtonBase button, string commandName)
        {
            BehaviorCollection behaviors = GetBehaviors(button);
            foreach (Behavior behavior in behaviors) {
                CommandBehavior commandBehavior = behavior as CommandBehavior;
                if (commandBehavior != null) {
                    if (String.IsNullOrEmpty(commandName)) {
                        behaviors.Remove(commandBehavior);
                    }
                    else {
                        commandBehavior.CommandName = commandName;
                    }
                    return;
                }
            }

            if (String.IsNullOrEmpty(commandName) == false) {
                CommandBehavior commandBehavior = new CommandBehavior();
                commandBehavior.CommandName = commandName;

                behaviors.Add(commandBehavior);
            }
        }
Exemple #23
0
        /// <summary>
        /// Gets the command name associated with the specified Button.
        /// </summary>
        /// <param name="button">The Button to lookup.</param>
        /// <returns>The command name associated with the Button; null if there is none.</returns>
        public static string GetCommand(ButtonBase button)
        {
            BehaviorCollection behaviors = (BehaviorCollection)button.GetValue(BehaviorsProperty);
            if (behaviors != null) {
                foreach (Behavior behavior in behaviors) {
                    CommandBehavior commandBehavior = behavior as CommandBehavior;
                    if (commandBehavior != null) {
                        return commandBehavior.CommandName;
                    }
                }
            }

            return null;
        }
Exemple #24
0
 public static ICommand GetCommand(ButtonBase buttonBase)
 {
     if (buttonBase == null) throw new System.ArgumentNullException("buttonBase");
     return buttonBase.GetValue(CommandProperty) as ICommand;
 }
        private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ButtonBase b = (ButtonBase)d;

            b.OnCommandChanged((ICommand)e.OldValue, (ICommand)e.NewValue);
        }
Exemple #26
0
 /// <summary>
 /// 引发 <see cref="Primitives.ButtonBase.Click" /> 路由事件。
 /// </summary>
 /// <param name="buttonBase">要引发路由事件的按钮</param>
 public static void OnClick(this Primitives.ButtonBase buttonBase)
 {
     buttonBase.GetType().GetMethod(nameof(OnClick), BindingFlags.Instance | BindingFlags.NonPublic).Invoke(buttonBase, null);
 }
        public override void OnApplyTemplate()
        {
            this.UnsubscribeFromTemplatePartEvents();

            base.OnApplyTemplate();

            this._closeButton = GetTemplateChild(PART_CloseButton) as ButtonBase;

            if (this._closed != null)
            {
                this._closed.Completed -= new EventHandler(this.Closing_Completed);
            }

            if (this._opened != null)
            {
                this._opened.Completed -= new EventHandler(this.Opening_Completed);
            }

            this._root = GetTemplateChild(PART_Root) as FrameworkElement;
            this._resizer = GetTemplateChild(PART_Resizer) as FrameworkElement;

            if (this._root != null)
            {
                Collection<VisualStateGroup> groups = VisualStateManager.GetVisualStateGroups(this._root) as Collection<VisualStateGroup>;

                if (groups != null)
                {
                    System.Collections.IList states = (from stategroup in groups
                                                       where stategroup.Name == FloatableWindow.VSMGROUP_Window
                                                       select stategroup.States).FirstOrDefault();
                    Collection<VisualState> statesCol = states as Collection<VisualState>;

                    if (statesCol != null)
                    {
                        this._closed = (from state in statesCol
                                        where state.Name == FloatableWindow.VSMSTATE_StateClosing
                                        select state.Storyboard).FirstOrDefault();

                        this._opened = (from state in statesCol
                                        where state.Name == FloatableWindow.VSMSTATE_StateOpening
                                        select state.Storyboard).FirstOrDefault();
                    }
                }
                //TODO: Figure out why I can't wire up the event below in SubscribeToTemplatePartEvents
                this._root.MouseLeftButtonDown += new MouseButtonEventHandler(this.ContentRoot_MouseLeftButtonDown);

                if (this._resizer != null)
                {
                    if (this.ResizeMode == ResizeMode.CanResize)
                    {
                        this._resizer.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Resizer_MouseLeftButtonDown);
                        this._resizer.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(Resizer_MouseLeftButtonUp);
                        this._resizer.MouseMove += new System.Windows.Input.MouseEventHandler(Resizer_MouseMove);
                        this._resizer.MouseEnter += new MouseEventHandler(Resizer_MouseEnter);
                        this._resizer.MouseLeave += new MouseEventHandler(Resizer_MouseLeave);
                    }
                    else
                    {
                        this._resizer.Opacity = 0;
                    }
                }
            }

            this.ContentRoot = GetTemplateChild(PART_ContentRoot) as FrameworkElement;

            this._chrome = GetTemplateChild(PART_Chrome) as FrameworkElement;

            this._overlay = GetTemplateChild(PART_Overlay) as FrameworkElement;

            this.SubscribeToTemplatePartEvents();
            this.SubscribeToStoryBoardEvents();

            // Update overlay size
            if (this.IsOpen)
            {
                this._desiredContentHeight = this.Height;
                this._desiredContentWidth = this.Width;
                this.UpdateOverlaySize();
                this.UpdateRenderTransform();
                this._isOpening = true;
                try
                {
                    this.ChangeVisualState();
                }
                finally
                {
                    this._isOpening = false;
                }
            }
        }
Exemple #28
0
        /*
         * Protected override methods
         * 
        */

        #region Overrides

        /// <summary>
        /// OnApplyTemplate override
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // set up the event handler for the template parts
            _toggleButton = this.Template.FindName("PART_DropDown", this) as ToggleButton;
            if (_toggleButton != null)
            {
                // create a context menu for the togglebutton
                ContextMenu cm = new ContextMenu { PlacementTarget = _toggleButton, Placement = PlacementMode.Bottom };

                // create a binding between the togglebutton's IsChecked Property
                // and the Context Menu's IsOpen Property
                Binding b = new Binding
                {
                    Source = _toggleButton,
                    Mode = BindingMode.TwoWay,
                    Path = new PropertyPath(ToggleButton.IsCheckedProperty)
                };

                cm.SetBinding(ContextMenu.IsOpenProperty, b);

                _toggleButton.ContextMenu = cm;
                _toggleButton.Checked += DropdownButton_Checked;
            }

            ScrollViewer scrollViewer = this.Template.FindName("PART_ScrollViewer", this) as ScrollViewer;

            // set up event handlers for the RepeatButtons Click event
            RepeatButton repeatLeft = this.Template.FindName("PART_RepeatLeft", this) as RepeatButton;
            if (repeatLeft != null)
            {
                repeatLeft.Click += delegate
                {
                    if (scrollViewer != null)
                        scrollViewer.LineLeft();
                };
            }

            RepeatButton repeatRight = this.Template.FindName("PART_RepeatRight", this) as RepeatButton;
            if (repeatRight != null)
            {
                repeatRight.Click += delegate
                {
                    if (scrollViewer != null)
                        scrollViewer.LineRight();
                };
            }

            // set up the event handler for the 'New Tab' Button Click event
            _addNewButton = this.Template.FindName("PART_NewTabButton", this) as ButtonBase;
            if (_addNewButton != null)
                _addNewButton.Click += ((sender, routedEventArgs) => AddTabItem());
        }
Exemple #29
0
 public static void SetCommandParameter(ButtonBase buttonBase, object parameter)
 {
     if (buttonBase == null) throw new System.ArgumentNullException("buttonBase");
     buttonBase.SetValue(CommandParameterProperty, parameter);
 }
    public override void OnApplyTemplate()
    {
      base.OnApplyTemplate();

      ElementCloseButton = GetTemplateChild(ElementCloseButtonName) as ButtonBase;
      ElementNextButton = GetTemplateChild(ElementNextButtonName) as ButtonBase;
      ElementPreviousButton = GetTemplateChild(ElementPreviousButtonName) as ButtonBase;

      ElementTitleTextBlock = GetTemplateChild(ElementTitleTextBlockName) as TextBlock;
      ElementMessageTextBlock = GetTemplateChild(ElementMessageTextBlockName) as TextBlock;

      ElementDetailTextBlock = GetTemplateChild(ElementDetailTextBlockName) as TextBlock;
      ElementDetailPopup = GetTemplateChild(ElementDetailPopupName) as Popup;

      ElementDetailPopupChild = ElementDetailPopup != null
        ? ElementDetailPopup.Child as FrameworkElement
        : null;

      SizeChanged += ElementPopupChild_SizeChanged;
      if (ElementDetailPopupChild != null)
      {
        ElementDetailPopupChild.MouseEnter += ElementPopupChild_MouseEnter;
        ElementDetailPopupChild.MouseLeave += ElementPopupChild_MouseLeave;
        ElementDetailPopupChild.SizeChanged += ElementPopupChild_SizeChanged;
      }

      ElementCountBorder = GetTemplateChild(ElementCountBorderName) as Border;
      ElementCountTextBlock = GetTemplateChild(ElementCountTextBlockName) as TextBlock;

      UpdateBinding();
      UpdateCommands();
      UpdateVisibility();
    }
Exemple #31
0
        /// <summary>
        /// Invoked when the content of this control has been changed. This method will add the dynamic controls automatically.
        /// </summary>
        /// <param name="oldContent">Old content.</param>
        /// <param name="newContent">New content.</param>
        protected override void OnContentChanged(object oldContent, object newContent)
        {
            base.OnContentChanged(oldContent, newContent);

            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            if (!WrapControlHelper.CanBeWrapped(newContent as FrameworkElement) || _isWrapped)
            {
                return;
            }

            var languageService = ServiceLocator.Default.ResolveType<ILanguageService>();

            if (IsOKButtonAvailable)
            {
                var button = new DataWindowButton(languageService.GetString("OK"), OnOkExecute, OnOkCanExecute);
                button.IsDefault = (DefaultButton == DataWindowDefaultButton.OK);
                _buttons.Add(button);
            }
            if (IsCancelButtonAvailable)
            {
                var button = new DataWindowButton(languageService.GetString("Cancel"), OnCancelExecute, OnCancelCanExecute);
                button.IsCancel = true;
                _buttons.Add(button);
            }
            if (IsApplyButtonAvailable)
            {
                var button = new DataWindowButton(languageService.GetString("Apply"), OnApplyExcute, OnApplyCanExecute);
                button.IsDefault = (DefaultButton == DataWindowDefaultButton.Apply);
                _buttons.Add(button);
            }
            if (IsCloseButtonAvailable)
            {
                var button = new DataWindowButton(languageService.GetString("Close"), OnCloseExecute, OnCloseCanExecute);
                button.IsDefault = (DefaultButton == DataWindowDefaultButton.Close);
                _buttons.Add(button);
            }

            foreach (DataWindowButton button in _buttons)
            {
                _commands.Add(button.Command);
            }

            var wrapOptions = WrapOptions.GenerateWarningAndErrorValidatorForDataContext;
            switch (_infoBarMessageControlGenerationMode)
            {
                case InfoBarMessageControlGenerationMode.None:
                    break;

                case InfoBarMessageControlGenerationMode.Inline:
                    wrapOptions |= WrapOptions.GenerateInlineInfoBarMessageControl;
                    break;

                case InfoBarMessageControlGenerationMode.Overlay:
                    wrapOptions |= WrapOptions.GenerateOverlayInfoBarMessageControl;
                    break;
            }

            _isWrapped = true;

            var contentGrid = WrapControlHelper.Wrap((FrameworkElement)newContent, wrapOptions, _buttons.ToArray(), this);

            var internalGrid = contentGrid.FindVisualDescendant(obj => (obj is FrameworkElement) && string.Equals(((FrameworkElement)obj).Name, WrapControlHelper.InternalGridName)) as Grid;
            if (internalGrid != null)
            {
#if SILVERLIGHT
                internalGrid.Style = Application.Current.Resources["WindowGridStyle"] as Style;
#else
                internalGrid.SetResourceReference(StyleProperty, "WindowGridStyle");

                ((UIElement)newContent).FocusFirstControl();
#endif

                _defaultOkCommand = (from button in _buttons
                                     where button.IsDefault
                                     select button.Command).FirstOrDefault();
                _defaultOkElement = WrapControlHelper.GetWrappedElement<ButtonBase>(contentGrid, WrapControlHelper.DefaultOkButtonName);

                _defaultCancelCommand = (from button in _buttons
                                         where button.IsCancel
                                         select button.Command).FirstOrDefault();

                InternalGrid = internalGrid;

                OnInternalGridChanged();
            }
        }
Exemple #32
0
        /// <summary>
        /// Sets the action associated with the specified Button.
        /// </summary>
        /// <param name="button">The Button to associate the action with.</param>
        /// <param name="action">The action to associate with the button.</param>
        public static void SetAction(ButtonBase button, TriggerAction action)
        {
            if (action == null) {
                return;
            }

            TriggerCollection triggers = GetTriggers(button);

            foreach (Trigger trigger in triggers) {
                ClickTrigger clickTrigger = trigger as ClickTrigger;
                clickTrigger.Action = action;
            }

            ClickTrigger newTrigger = new ClickTrigger();
            newTrigger.Action = action;

            triggers.Add(newTrigger);
        }
        /// <summary>
        /// override to get the templated controls
        /// </summary>
        public override void OnApplyTemplate()
        {
            //Focus the popup if it exists in the Control template
            Popup popup = GetTemplateChild("Popup") as Popup;
            if (popup != null)
            {
                popup.Opened += delegate
                {
                    popup.Focus();
                };
            }

            datesList = GetTemplateChild("PART_Dates") as Selector;
            backButton = GetTemplateChild("PART_MonthBack") as ButtonBase;
            forwardButton = GetTemplateChild("PART_MonthForward") as ButtonBase;
        
            backButton.Click += BackButtonClick;
            forwardButton.Click += ForwardButtonClick;
            datesList.SelectionChanged += DatesListSelectionChanged;
            //if the control is a listbox then set the selection mode
            ListBox list = datesList as ListBox;
            if (list != null && DatesSelectionMode != SelectionMode.Single)
            {
                CurrentlySelectedDates = new ObservableCollection<DateTime>();
                list.SelectionMode = DatesSelectionMode;
            }
            
            ReBindListOfDays();
        }
        /// <summary>
        ///     Called when IsPressedProperty is changed on "d."
        /// </summary>
        private static void OnIsPressedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ButtonBase ctrl = (ButtonBase)d;

            ctrl.OnIsPressedChanged(e);
        }
Exemple #35
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            IncreaseButton = GetTemplateChild(PART_IncreaseButton) as ButtonBase;
            DecreaseButton = GetTemplateChild(PART_DecreaseButton) as ButtonBase;

            SetButtonUsage();
        }