コード例 #1
0
        protected override Control CreatePresenter()
        {
            var commandBar = new CommandBarFlyoutCommandBar();

            commandBar.Opened += delegate
            {
                SetCurrentValue(ShowModeProperty, FlyoutShowMode.Standard);
            };

            SharedHelpers.CopyList(PrimaryCommands, commandBar.PrimaryCommands);
            SharedHelpers.CopyList(SecondaryCommands, commandBar.SecondaryCommands);

            SetSecondaryCommandsToCloseWhenExecuted();

            FlyoutPresenter presenter = new FlyoutPresenter
            {
                Background             = null,
                Foreground             = null,
                BorderBrush            = null,
                MinWidth               = 0,
                MaxWidth               = double.PositiveInfinity,
                MinHeight              = 0,
                MaxHeight              = double.PositiveInfinity,
                BorderThickness        = new Thickness(0),
                Padding                = new Thickness(0),
                Content                = commandBar,
                CornerRadius           = new CornerRadius(0),
                IsDefaultShadowEnabled = false
            };

            commandBar.SetOwningFlyout(this);

            m_commandBar = commandBar;
            return(presenter);
        }
コード例 #2
0
ファイル: NavigationViewItem.cs プロジェクト: ldn42/ModernWpf
        void UpdateVisualStateForNavigationViewPositionChange()
        {
            var position  = Position;
            var stateName = c_OnLeftNavigation;

            bool handled = false;

            switch (position)
            {
            case NavigationViewRepeaterPosition.LeftNav:
            case NavigationViewRepeaterPosition.LeftFooter:
                if (SharedHelpers.IsRS4OrHigher() && false /*Application.Current.FocusVisualKind == FocusVisualKind.Reveal*/)
                {
                    // OnLeftNavigationReveal is introduced in RS6.
                    // Will fallback to stateName for the customer who re-template rs5 NavigationViewItem
                    if (VisualStateManager.GoToState(this, c_OnLeftNavigationReveal, false /*useTransitions*/))
                    {
                        handled = true;
                    }
                }
                break;

            case NavigationViewRepeaterPosition.TopPrimary:
            case NavigationViewRepeaterPosition.TopFooter:
                if (SharedHelpers.IsRS4OrHigher() && false /*Application.Current.FocusVisualKind == FocusVisualKind.Reveal*/)
                {
                    stateName = c_OnTopNavigationPrimaryReveal;
                }
                else
                {
                    stateName = c_OnTopNavigationPrimary;
                }
                break;

            case NavigationViewRepeaterPosition.TopOverflow:
                stateName = c_OnTopNavigationOverflow;
                break;
            }

            if (!handled)
            {
                VisualStateManager.GoToState(this, stateName, false /*useTransitions*/);
            }
        }
コード例 #3
0
        public CommandBarFlyout()
        {
            PrimaryCommands   = new ObservableCollection <ICommandBarElement>();
            SecondaryCommands = new ObservableCollection <ICommandBarElement>();

            PrimaryCommands.CollectionChanged += (object sender, NotifyCollectionChangedEventArgs args) =>
            {
                if (m_commandBar != null)
                {
                    SharedHelpers.ForwardCollectionChange((ObservableCollection <ICommandBarElement>)sender, m_commandBar.PrimaryCommands, args);
                }
            };

            SecondaryCommands.CollectionChanged += (object sender, NotifyCollectionChangedEventArgs args) =>
            {
                var commandBar = m_commandBar;
                if (commandBar != null)
                {
                    var source = (ObservableCollection <ICommandBarElement>)sender;
                    SharedHelpers.ForwardCollectionChange(source, commandBar.SecondaryCommands, args);

                    // We want to ensure that any interaction with secondary items causes the CommandBarFlyout
                    // to close, so we'll attach a Click handler to any buttons and Checked/Unchecked handlers
                    // to any toggle buttons that we get and close the flyout when they're invoked.
                    // The only exception is buttons with flyouts - in that case, clicking on the button
                    // will just open the flyout rather than executing an action, so we don't want that to
                    // do anything.
                    RoutedEventHandler closeFlyoutFunc = delegate { Hide(); };

                    // TODO
                    switch (args.Action)
                    {
                    case NotifyCollectionChangedAction.Replace:
                    {
                        var element      = (ICommandBarElement)args.NewItems[0];
                        var oldElement   = (ICommandBarElement)args.OldItems[0];
                        var button       = element as AppBarButton;
                        var toggleButton = element as AppBarToggleButton;

                        RevokeAndRemove(m_secondaryButtonClickRevokerByElementMap, oldElement);
                        RevokeAndRemove(m_secondaryToggleButtonCheckedRevokerByElementMap, oldElement);
                        RevokeAndRemove(m_secondaryToggleButtonUncheckedRevokerByElementMap, oldElement);

                        if (button != null && button.Flyout == null)
                        {
                            m_secondaryButtonClickRevokerByElementMap[element] = new RoutedEventHandlerRevoker(
                                button, ButtonBase.ClickEvent, closeFlyoutFunc);
                            RevokeAndRemove(m_secondaryToggleButtonCheckedRevokerByElementMap, element);
                            RevokeAndRemove(m_secondaryToggleButtonUncheckedRevokerByElementMap, element);
                        }
                        else if (toggleButton != null)
                        {
                            RevokeAndRemove(m_secondaryButtonClickRevokerByElementMap, element);
                            m_secondaryToggleButtonCheckedRevokerByElementMap[element] = new RoutedEventHandlerRevoker(
                                button, ToggleButton.CheckedEvent, closeFlyoutFunc);
                            m_secondaryToggleButtonUncheckedRevokerByElementMap[element] = new RoutedEventHandlerRevoker(
                                button, ToggleButton.UncheckedEvent, closeFlyoutFunc);
                        }
                        else
                        {
                            RevokeAndRemove(m_secondaryButtonClickRevokerByElementMap, element);
                            RevokeAndRemove(m_secondaryToggleButtonCheckedRevokerByElementMap, element);
                            RevokeAndRemove(m_secondaryToggleButtonUncheckedRevokerByElementMap, element);
                        }
                        break;
                    }

                    case NotifyCollectionChangedAction.Add:
                    {
                        var element      = (ICommandBarElement)args.NewItems[0];
                        var button       = element as AppBarButton;
                        var toggleButton = element as AppBarToggleButton;

                        if (button != null && button.Flyout == null)
                        {
                            m_secondaryButtonClickRevokerByElementMap[element] = new RoutedEventHandlerRevoker(
                                button, ButtonBase.ClickEvent, closeFlyoutFunc);
                        }
                        else if (toggleButton != null)
                        {
                            m_secondaryToggleButtonCheckedRevokerByElementMap[element] = new RoutedEventHandlerRevoker(
                                button, ToggleButton.CheckedEvent, closeFlyoutFunc);
                            m_secondaryToggleButtonUncheckedRevokerByElementMap[element] = new RoutedEventHandlerRevoker(
                                button, ToggleButton.UncheckedEvent, closeFlyoutFunc);
                        }
                        break;
                    }

                    case NotifyCollectionChangedAction.Remove:
                    {
                        var element = (ICommandBarElement)args.OldItems[0];
                        RevokeAndRemove(m_secondaryButtonClickRevokerByElementMap, element);
                        RevokeAndRemove(m_secondaryToggleButtonCheckedRevokerByElementMap, element);
                        RevokeAndRemove(m_secondaryToggleButtonUncheckedRevokerByElementMap, element);
                        break;
                    }

                    case NotifyCollectionChangedAction.Move:
                        break;

                    case NotifyCollectionChangedAction.Reset:
                        SetSecondaryCommandsToCloseWhenExecuted();
                        break;

                    default:
                        Debug.Assert(false);
                        break;
                    }
                }
            };

            Opening += delegate
            {
                AreOpenCloseAnimationsEnabled = true;

                if (m_commandBar.HasOpenAnimation())
                {
                    InternalPopup.SuppressFadeAnimation = true;
                }
                else
                {
                    InternalPopup.SuppressFadeAnimation = false;
                }

                if (ShowMode == FlyoutShowMode.Standard)
                {
                    m_commandBar.IsOpen = true;
                }
            };

            Opened += delegate
            {
                if (m_commandBar != null)
                {
                    if (m_commandBar.HasOpenAnimation())
                    {
                        m_commandBar.PlayOpenAnimation();
                    }
                    else
                    {
                        AreOpenCloseAnimationsEnabled = false;
                    }
                }
            };

            Closing += delegate
            {
                var commandBar = m_commandBar;
                if (commandBar != null)
                {
                    if (!m_isClosingAfterCloseAnimation && commandBar.HasCloseAnimation())
                    {
                        //args.Cancel(true);

                        commandBar.PlayCloseAnimation(() =>
                        {
                            m_isClosingAfterCloseAnimation = true;
                            Hide();
                            m_isClosingAfterCloseAnimation = false;
                        });
                        commandBar.IsOpen = false;
                    }

                    //CommandBarFlyoutCommandBar.Closed will be called when
                    //clicking the more (...) button, we clear the translations
                    //here
                    commandBar.ClearShadow();
                }
            };

            Closed += delegate
            {
                if (m_commandBar != null)
                {
                    if (m_commandBar.IsOpen)
                    {
                        m_commandBar.IsOpen = false;
                    }
                }
            };
        }
コード例 #4
0
ファイル: NumberBox.cs プロジェクト: rinchenlama19xx/theme
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var spinDownName = Strings.NumberBoxDownSpinButtonName;
            var spinUpName   = Strings.NumberBoxUpSpinButtonName;

            if (GetTemplateChild(c_numberBoxDownButtonName) is RepeatButton spinDown)
            {
                spinDown.Click += OnSpinDownClick;

                // Do localization for the down button
                if (string.IsNullOrEmpty(AutomationProperties.GetName(spinDown)))
                {
                    AutomationProperties.SetName(spinDown, spinDownName);
                }
            }

            if (GetTemplateChild(c_numberBoxUpButtonName) is RepeatButton spinUp)
            {
                spinUp.Click += OnSpinUpClick;

                // Do localization for the up button
                if (string.IsNullOrEmpty(AutomationProperties.GetName(spinUp)))
                {
                    AutomationProperties.SetName(spinUp, spinUpName);
                }
            }

            UpdateHeaderPresenterState();

            m_textBox = GetTextBox();
            TextBox GetTextBox()
            {
                var textBox = GetTemplateChild(c_numberBoxTextBoxName) as TextBox;

                if (textBox != null)
                {
                    if (SharedHelpers.IsRS3OrHigher())
                    {
                        // Listen to PreviewKeyDown because textbox eats the down arrow key in some circumstances.
                        textBox.PreviewKeyDown += OnNumberBoxKeyDown;
                    }
                    else
                    {
                        // This is better than nothing.
                        textBox.KeyDown += OnNumberBoxKeyDown;
                    }

                    textBox.KeyUp += OnNumberBoxKeyUp;

                    // Listen to NumberBox::CornerRadius changes so that we can enfore the T-rule for the textbox in SpinButtonPlacementMode::Inline.
                    // We need to explicitly go to the corresponding visual state each time the NumberBox' CornerRadius is changed in order for the new
                    // corner radius values to be filtered correctly.
                    // If we only go to the SpinButtonsVisible visual state whenever the SpinButtonPlacementMode is changed to Inline, all subsequent
                    // corner radius changes would apply to all four textbox corners (this can be easily seen in the CornerRadius test page of the MUXControlsTestApp).
                    // This will break the T-rule in the Inline SpinButtonPlacementMode.
                    // Not needed for WPF.

                    /*
                     * if (SharedHelpers.IsControlCornerRadiusAvailable())
                     * {
                     *  RegisterPropertyChanged(Control.CornerRadiusProperty, OnCornerRadiusPropertyChanged);
                     * }
                     */
                }
                return(textBox);
            }

            m_popup = GetTemplateChild(c_numberBoxPopupName) as Popup;

            if (m_popup != null)
            {
                if (m_popup.HasDefaultValue(Popup.PlacementTargetProperty))
                {
                    m_popup.PlacementTarget = m_textBox;
                }

                m_popupRepositionHelper = new PopupRepositionHelper(m_popup, this);
            }

            if (GetTemplateChild(c_numberBoxPopupDownButtonName) is RepeatButton popupSpinDown)
            {
                popupSpinDown.Click += OnSpinDownClick;
            }

            if (GetTemplateChild(c_numberBoxPopupUpButtonName) is RepeatButton popupSpinUp)
            {
                popupSpinUp.Click += OnSpinUpClick;
            }

            IsEnabledChanged += OnIsEnabledChanged;

            // .NET rounds to 12 significant digits when displaying doubles, so we will do the same.
            //m_displayRounder.SignificantDigits(12);

            UpdateSpinButtonPlacement();
            UpdateSpinButtonEnabled();

            UpdateVisualStateForIsEnabledChange();

            if (ReadLocalValue(ValueProperty) == DependencyProperty.UnsetValue &&
                ReadLocalValue(TextProperty) != DependencyProperty.UnsetValue)
            {
                // If Text has been set, but Value hasn't, update Value based on Text.
                UpdateValueToText();
            }
            else
            {
                UpdateTextToValue();
            }
        }
コード例 #5
0
ファイル: SharedHelpers.cs プロジェクト: zz110/ModernWpf
 public static object FindInApplicationResources(string resource, object defaultValue)
 {
     return(SharedHelpers.FindResource(resource, Application.Current.Resources, defaultValue));
 }