Exemplo n.º 1
0
        protected override string GetNameCore()
        {
            string name = base.GetNameCore();

            if (Owner is ProgressRing progressRing)
            {
                if (progressRing.IsActive)
                {
                    return(ResourceAccessor.GetLocalizedStringResource(SR_ProgressRingIndeterminateStatus) + name);
                }
            }
            return(name);
        }
Exemplo n.º 2
0
        private void UpdateSeverity()
        {
            var severityState = "Informational";

            switch (Severity)
            {
            case InfoBarSeverity.Success:
                severityState = "Success";
                break;

            case InfoBarSeverity.Warning:
                severityState = "Warning";
                break;

            case InfoBarSeverity.Error:
                severityState = "Error";
                break;
            }
            ;

            if (m_standardIconTextBlock is FrameworkElement iconTextblock)
            {
                AutomationProperties.SetName(iconTextblock, ResourceAccessor.GetLocalizedStringResource(GetIconSeverityLevelResourceName(Severity)));
            }

            VisualStateManager.GoToState(this, severityState, false);
        }
Exemplo n.º 3
0
    public MessageDialogContentDialog(MessageDialog messageDialog)
    {
        DefaultStyleKey = typeof(ContentDialog);
        _messageDialog  = messageDialog ?? throw new ArgumentNullException(nameof(messageDialog));

        var styleOverriden = TryApplyStyle(WinRTFeatureConfiguration.MessageDialog.StyleOverride);

        if (!styleOverriden)
        {
            // WinUI provides a modern style for ContentDialog, which is not applied automatically.
            // Force apply it if available.
            TryApplyStyle("DefaultContentDialogStyle");
        }

        _commands           = _messageDialog.Commands.ToList();
        _cancelCommandIndex = _messageDialog.CancelCommandIndex;

        Content = _messageDialog.Content;
        Title   = _messageDialog.Title;

        if (_commands.Count == 0)
        {
            // Only show a close button
            var closeText = ResourceAccessor.GetLocalizedStringResource("NavigationCloseButtonName");
            _commands.Add(new UICommand(closeText));
        }

        PrimaryButtonText   = _commands[0].Label;
        SecondaryButtonText = _commands.Count > 1 ? _commands[1].Label : null;
        CloseButtonText     = _commands.Count > 2 ? _commands[2].Label : null;

        DefaultButton = (ContentDialogButton)(_messageDialog.DefaultCommandIndex + 1);         // ContentDialogButton indexed from 1
    }
Exemplo n.º 4
0
        private string GetValueString(Color color, int value)
        {
            if (DownlevelHelper.ToDisplayNameExists())
            {
                string resourceStringWithName;
                switch (_owner.ColorChannel)
                {
                case ColorPickerHsvChannel.Hue:
                    resourceStringWithName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringHueSliderWithColorName);
                    break;

                case ColorPickerHsvChannel.Saturation:
                    resourceStringWithName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringSaturationSliderWithColorName);
                    break;

                case ColorPickerHsvChannel.Value:
                    resourceStringWithName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringValueSliderWithColorName);
                    break;

                default:
                    return(string.Empty);
                }

                return(string.Format(
                           CultureInfo.CurrentUICulture,
                           resourceStringWithName,
                           value,
                           ColorHelper.ToDisplayName(color)));
            }
            else
            {
                string resourceStringWithoutName;
                switch (_owner.ColorChannel)
                {
                case ColorPickerHsvChannel.Hue:
                    resourceStringWithoutName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringHueSliderWithoutColorName);
                    break;

                case ColorPickerHsvChannel.Saturation:
                    resourceStringWithoutName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringSaturationSliderWithoutColorName);
                    break;

                case ColorPickerHsvChannel.Value:
                    resourceStringWithoutName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringValueSliderWithoutColorName);
                    break;

                default:
                    return(string.Empty);
                }

                return(string.Format(
                           CultureInfo.CurrentUICulture,
                           resourceStringWithoutName,
                           value));
            }
        }
Exemplo n.º 5
0
        protected override void OnApplyTemplate()
        {
            UnregisterEvents();

            m_primaryButton   = this.GetTemplateChild("PrimaryButton") as Button;
            m_secondaryButton = this.GetTemplateChild("SecondaryButton") as Button;

            var primaryButton = m_primaryButton;

            if (primaryButton != null)
            {
                primaryButton.Click += OnClickPrimary;

                m_pressedPrimaryRevoker     = primaryButton.RegisterPropertyChangedCallback(ButtonBase.IsPressedProperty, OnVisualPropertyChanged);
                m_pointerOverPrimaryRevoker = primaryButton.RegisterPropertyChangedCallback(ButtonBase.IsPointerOverProperty, OnVisualPropertyChanged);

                // Register for pointer events so we can keep track of the last used pointer type
                primaryButton.PointerEntered     += OnPointerEvent;
                primaryButton.PointerExited      += OnPointerEvent;
                primaryButton.PointerPressed     += OnPointerEvent;
                primaryButton.PointerReleased    += OnPointerEvent;
                primaryButton.PointerCanceled    += OnPointerEvent;
                primaryButton.PointerCaptureLost += OnPointerEvent;
            }

            var secondaryButton = m_secondaryButton;

            if (secondaryButton != null)
            {
                // Do localization for the secondary button
                var secondaryName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_SplitButtonSecondaryButtonName);
                AutomationProperties.SetName(secondaryButton, secondaryName);

                secondaryButton.Click += OnClickSecondary;

                m_pressedSecondaryRevoker     = secondaryButton.RegisterPropertyChangedCallback(ButtonBase.IsPressedProperty, OnVisualPropertyChanged);
                m_pointerOverSecondaryRevoker = secondaryButton.RegisterPropertyChangedCallback(ButtonBase.IsPointerOverProperty, OnVisualPropertyChanged);

                // Register for pointer events so we can keep track of the last used pointer type
                secondaryButton.PointerEntered     += OnPointerEvent;
                secondaryButton.PointerExited      += OnPointerEvent;
                secondaryButton.PointerPressed     += OnPointerEvent;
                secondaryButton.PointerReleased    += OnPointerEvent;
                secondaryButton.PointerCanceled    += OnPointerEvent;
                secondaryButton.PointerCaptureLost += OnPointerEvent;
            }

            // Register events on flyout
            RegisterFlyoutEvents();

            UpdateVisualStates();

            m_hasLoaded = true;
        }
        protected override string GetNameCore()
        {
            string name = base.GetNameCore();

            if (Owner is ProgressBar progressBar)
            {
                if (progressBar.ShowError)
                {
                    return(ResourceAccessor.GetLocalizedStringResource(SR_ProgressBarErrorStatus));
                }
                else if (progressBar.ShowPaused)
                {
                    return(ResourceAccessor.GetLocalizedStringResource(SR_ProgressBarPausedStatus));
                }
                else if (progressBar.IsIndeterminate)
                {
                    return(ResourceAccessor.GetLocalizedStringResource(SR_ProgressBarIndeterminateStatus));
                }
            }
            return(name);
        }
Exemplo n.º 7
0
        protected override string GetNameCore()
        {
            string nameString = base.GetNameCore();

            // If a name hasn't been provided by AutomationProperties.Name in markup,
            // then we'll return the default value.
            if (string.IsNullOrEmpty(nameString))
            {
                nameString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_AutomationNameColorSpectrum);
            }

            return(nameString);
        }
Exemplo n.º 8
0
        private void UpdateVisibility(bool notify = true, bool force = true)
        {
            var peer = FrameworkElementAutomationPeer.FromElement(this) as InfoBarAutomationPeer;

            if (!m_applyTemplateCalled)
            {
                // ApplyTemplate() hasn't been called yet but IsOpen has already been set.
                // Since this method will be called again shortly from ApplyTemplate, we'll just wait and send a notification then.
                m_notifyOpen = true;
            }
            else
            {
                // Don't do any work if nothing has changed (unless we are forcing a update)
                if (force || IsOpen != m_isVisible)
                {
                    if (IsOpen)
                    {
                        if (notify && peer != null)
                        {
                            var notificationString = StringUtil.FormatString(
                                ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_InfoBarOpenedNotification),
                                ResourceAccessor.GetLocalizedStringResource(GetIconSeverityLevelResourceName(Severity)),
                                Title,
                                Message);

                            peer.RaiseOpenedEvent(Severity, notificationString);
                        }

                        VisualStateManager.GoToState(this, "InfoBarVisible", false);
                        AutomationProperties.SetAccessibilityView(this, AccessibilityView.Control);
                        m_isVisible = true;
                    }
                    else
                    {
                        if (notify && peer != null)
                        {
                            var notificationString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_InfoBarClosedNotification);

                            peer.RaiseClosedEvent(Severity, notificationString);
                        }

                        VisualStateManager.GoToState(this, "InfoBarCollapsed", false);
                        AutomationProperties.SetAccessibilityView(this, AccessibilityView.Raw);
                        m_isVisible = false;
                    }
                }
            }
        }
Exemplo n.º 9
0
        protected override void OnApplyTemplate()
        {
            m_applyTemplateCalled = true;

            var closeButton = GetTemplateChild <Button>(c_closeButtonName);

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

                // Do localization for the close button
                if (string.IsNullOrEmpty(AutomationProperties.GetName(closeButton)))
                {
                    var closeButtonName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_InfoBarCloseButtonName);
                    AutomationProperties.SetName(closeButton, closeButtonName);
                }

                // Setup the tooltip for the close button
                var tooltip = new ToolTip();
                var closeButtonTooltipText = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_InfoBarCloseButtonTooltip);
                tooltip.Content = closeButtonTooltipText;
                ToolTipService.SetToolTip(closeButton, tooltip);
            }

            var iconTextblock = GetTemplateChild <FrameworkElement>(c_iconTextBlockName);

            if (iconTextblock != null)
            {
                m_standardIconTextBlock = iconTextblock;
                AutomationProperties.SetName(iconTextblock, ResourceAccessor.GetLocalizedStringResource(GetIconSeverityLevelResourceName(Severity)));
            }

            var contentRootGrid = GetTemplateChild <Button>(c_contentRootName);

            if (contentRootGrid != null)
            {
                AutomationProperties.SetLocalizedLandmarkType(contentRootGrid, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_InfoBarCustomLandmarkName));
            }

            UpdateVisibility(m_notifyOpen, true);
            m_notifyOpen = false;

            UpdateSeverity();
            UpdateIcon();
            UpdateIconVisibility();
            UpdateCloseButton();
            UpdateForeground();
        }
Exemplo n.º 10
0
        private string GetValueString(Color color, Vector4 hsvColor)
        {
            var hue        = (uint)Math.Round(Hsv.GetHue(hsvColor));
            var saturation = (uint)Math.Round(Hsv.GetSaturation(hsvColor) * 100);
            var value      = (uint)Math.Round(Hsv.GetValue(hsvColor) * 100);

            if (DownlevelHelper.ToDisplayNameExists())
            {
                return(StringUtil.FormatString(
                           ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringColorSpectrumWithColorName),
                           ColorHelper.ToDisplayName(color),
                           hue, saturation, value));
            }
            else
            {
                return(StringUtil.FormatString(
                           ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringColorSpectrumWithoutColorName),
                           hue, saturation, value));
            }
        }
Exemplo n.º 11
0
        private void AppendButtonToNumberPanelList(int pageNumber, int numberOfPages)
        {
            Button button = new Button();

            button.Content = pageNumber;
            button.Click  += (sender, args) =>
            {
                var button = sender as Button;
                if (button != null)
                {
                    int unboxedValue = (int)button.Content;
                    SelectedPageIndex = unboxedValue - 1;
                }
            };
            // Set the default style of buttons
            button.Style = (Style)ResourceAccessor.ResourceLookup(this, c_numberPanelButtonStyleName);
            AutomationProperties.SetName(button, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlPageTextName) + " " + pageNumber);
            AutomationProperties.SetPositionInSet(button, pageNumber);
            AutomationProperties.SetSizeOfSet(button, numberOfPages);
            m_numberPanelElements.Add(button);
        }
Exemplo n.º 12
0
        string GetLocalizedPluralBadgeItemStringResource(int numericValue)
        {
            int    valueMod10 = numericValue % 10;
            string value;

            if (numericValue == 1)              // Singular
            {
                value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemSingular);
            }
            else if (numericValue == 2)             // 2
            {
                value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural7);
            }
            else if (numericValue == 3 || numericValue == 4)             // 3,4
            {
                value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural2);
            }
            else if (numericValue >= 5 && numericValue <= 10)             // 5-10
            {
                value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural5);
            }
            else if (numericValue >= 11 && numericValue <= 19)             // 11-19
            {
                value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural6);
            }
            else if (valueMod10 == 1)             // 21, 31, 41, etc.
            {
                value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural1);
            }
            else if (valueMod10 >= 2 && valueMod10 <= 4)             // 22-24, 32-34, 42-44, etc.
            {
                value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural3);
            }
            else             // Everything else... 0, 20, 25-30, 35-40, etc.
            {
                value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural4);
            }

            return(value);
        }
Exemplo n.º 13
0
        protected override string GetNameCore()
        {
            string returnHString = base.GetNameCore();

            // If a name hasn't been provided by AutomationProperties.Name in markup:
            if (string.IsNullOrEmpty(returnHString))
            {
                if (Owner is NavigationViewItem lvi)
                {
                    returnHString = SharedHelpers.TryGetStringRepresentationFromObject(lvi.Content);
                }
            }

            if (string.IsNullOrEmpty(returnHString))
            {
                // NB: It'll be up to the app to determine the automation label for
                // when they're using a PlaceholderValue vs. Value.

                returnHString = ResourceAccessor.GetLocalizedStringResource(SR_NavigationViewItemDefaultControlName);
            }

            return(returnHString);
        }
Exemplo n.º 14
0
        private string BuildEffectString(string priorString, string afterString, string dragString, string dragOverString)
        {
            string resultString;

            if (!string.IsNullOrEmpty(priorString) && !string.IsNullOrEmpty(afterString))
            {
                resultString = StringUtil.FormatString(
                    ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PlaceBetweenString),
                    dragString, priorString, afterString);
            }
            else if (!string.IsNullOrEmpty(priorString))
            {
                resultString = StringUtil.FormatString(
                    ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PlaceAfterString),
                    dragString, priorString);
            }
            else if (!string.IsNullOrEmpty(afterString))
            {
                resultString = StringUtil.FormatString(
                    ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PlaceBeforeString),
                    dragString, afterString);
            }
            else if (!string.IsNullOrEmpty(dragOverString))
            {
                resultString = StringUtil.FormatString(
                    ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_DropIntoNodeString),
                    dragString, dragOverString);
            }
            else
            {
                resultString = StringUtil.FormatString(
                    ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_FallBackPlaceString),
                    dragString);
            }

            return(resultString);
        }
Exemplo n.º 15
0
        private void InitializeTemplate()
        {
            _eventSubscriptions.Disposable = null;

            var registrations = new CompositeDisposable();

            var spinDownName = ResourceAccessor.GetLocalizedStringResource("NumberBoxDownSpinButtonName");
            var spinUpName   = ResourceAccessor.GetLocalizedStringResource("NumberBoxUpSpinButtonName");

            if (this.GetTemplateChild(c_numberBoxDownButtonName) is RepeatButton spinDown)
            {
                spinDown.Click += OnSpinDownClick;
                registrations.Add(() => 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;
                registrations.Add(() => spinUp.Click -= OnSpinUpClick);

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

            if (GetTemplateChild(c_numberBoxTextBoxName) is TextBox textBox)
            {
                textBox.KeyDown += OnNumberBoxKeyDown;
                registrations.Add(() => textBox.KeyDown -= OnNumberBoxKeyDown);
                textBox.KeyUp += OnNumberBoxKeyUp;
                registrations.Add(() => textBox.KeyUp -= OnNumberBoxKeyUp);

                m_textBox = textBox;
            }

            m_popup = GetTemplateChild(c_numberBoxPopupName) as Windows.UI.Xaml.Controls.Primitives.Popup;

            if (SharedHelpers.IsThemeShadowAvailable())
            {
                // UNO TODO
                //if (GetTemplateChildT(c_numberBoxPopupContentRootName) is UIElement popupRoot)
                //{
                //	if (!popupRoot.Shadow())
                //	{
                //		popupRoot.Shadow(ThemeShadow{});
                //		auto&& translation = popupRoot.Translation();

                //		const double shadowDepth = unbox_value<double>(SharedHelpers.FindResource(c_numberBoxPopupShadowDepthName, Application.Current().Resources(), box_value(c_popupShadowDepth)));

                //		popupRoot.Translation({ translation.x, translation.y, (float)shadowDepth });
                //	}
                //}
            }

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

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

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

            UpdateSpinButtonPlacement();
            UpdateSpinButtonEnabled();

            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();
            }

            _eventSubscriptions.Disposable = registrations;
        }
Exemplo n.º 16
0
 protected override string GetLocalizedControlTypeCore()
 {
     return(ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_RatingLocalizedControlType));
 }
Exemplo n.º 17
0
        void UpdateAutomationName()
        {
            Contact contact = Contact;
            string  automationName;
            string  contactName;

            // The AutomationName for the control is in the format: PersonName, BadgeInformation.
            // PersonName is set based on the name / initial properties in the order below.
            // if none exist, it defaults to "Person"
            if (IsGroup)
            {
                contactName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_GroupName);
            }
            else if (contact != null && !string.IsNullOrEmpty(contact.DisplayName))
            {
                contactName = contact.DisplayName;
            }
            else if (!string.IsNullOrEmpty(DisplayName))
            {
                contactName = DisplayName;
            }
            else if (!string.IsNullOrEmpty(Initials))
            {
                contactName = Initials;
            }
            else
            {
                contactName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PersonName);
            }

            // BadgeInformation portion of the AutomationName is set to 'n items' if there is a BadgeNumber,
            // or 'icon' for BadgeGlyph or BadgeImageSource. If BadgeText is specified, it will override
            // the string 'items' or 'icon'
            if (BadgeNumber > 0)
            {
                if (!string.IsNullOrEmpty(BadgeText))
                {
                    automationName = StringUtil.FormatString(
                        ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemTextOverride),
                        contactName,
                        BadgeNumber,
                        BadgeText);
                }
                else
                {
                    automationName = StringUtil.FormatString(
                        GetLocalizedPluralBadgeItemStringResource(BadgeNumber),
                        contactName,
                        BadgeNumber);
                }
            }
            else if (!string.IsNullOrEmpty(BadgeGlyph) || BadgeImageSource != null)
            {
                if (!string.IsNullOrEmpty(BadgeText))
                {
                    automationName = StringUtil.FormatString(
                        ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeIconTextOverride),
                        contactName,
                        BadgeText);
                }
                else
                {
                    automationName = StringUtil.FormatString(
                        ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeIcon),
                        contactName);
                }
            }
            else
            {
                automationName = contactName;
            }

            AutomationProperties.SetName(this, automationName);
        }
Exemplo n.º 18
0
        internal void UpdateDropTargetDropEffect(bool forceUpdate, bool isLeaving, TreeViewItem keyboardReorderedContainer)
        {
            //Preserve old value of string in case it's needed.
            string oldValue = m_dropTargetDropEffectString;

            TreeViewItem   dragItem     = null;
            AutomationPeer dragItemPeer = null;

            if (keyboardReorderedContainer != null)
            {
                dragItem = keyboardReorderedContainer;
            }
            else
            {
                var listItem = ContainerFromItem(m_draggedOverItem);
                if (listItem != null)
                {
                    dragItem = (TreeViewItem)listItem;
                }
            }

            if (dragItem != null)
            {
                var dragItemString = "";
                var itemBeforeInsertPositionString = "";
                var itemAfterInsertPositionString  = "";
                var draggedOverString = "";

                dragItemPeer = FrameworkElementAutomationPeer.FromElement(dragItem);
                if (dragItemPeer != null)
                {
                    dragItemString = dragItemPeer.GetName();
                }

                if (string.IsNullOrEmpty(dragItemString))
                {
                    dragItemString = ResourceAccessor.GetLocalizedStringResource(
                        ResourceAccessor.SR_DefaultItemString);
                }

                if (isLeaving)
                {
                    m_dropTargetDropEffectString = StringUtil.FormatString(
                        ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_CancelDraggingString),
                        dragItemString);
                }
                else
                {
                    //unused variables in MUX source
                    //TreeViewItem itemAfterInsertPosition = null;
                    //TreeViewItem itemBeforeInsertPosition = null;

                    if (m_draggedOverItem != null)
                    {
                        AutomationPeer draggedOverItemPeer = FrameworkElementAutomationPeer.FromElement(m_draggedOverItem);
                        if (draggedOverItemPeer != null)
                        {
                            draggedOverString = draggedOverItemPeer.GetName();
                        }
                    }
                    else
                    {
                        int insertIndex       = -1;
                        int afterInsertIndex  = -1;
                        int beforeInsertIndex = -1;
                        var dragItemIndex     = IndexFromContainer(dragItem);

                        if (keyboardReorderedContainer != null)
                        {
                            insertIndex = dragItemIndex;
                        }
                        else
                        {
                            insertIndex = m_emptySlotIndex;
                        }

                        if (insertIndex != -1)
                        {
                            afterInsertIndex  = insertIndex + 1;
                            beforeInsertIndex = insertIndex - 1;
                        }

                        if (insertIndex > dragItemIndex)
                        {
                            beforeInsertIndex++;
                        }
                        else if (insertIndex < dragItemIndex)
                        {
                            afterInsertIndex--;
                        }

                        itemBeforeInsertPositionString = GetAutomationName(beforeInsertIndex);
                        itemAfterInsertPositionString  = GetAutomationName(afterInsertIndex);
                    }

                    m_dropTargetDropEffectString = BuildEffectString(itemBeforeInsertPositionString, itemAfterInsertPositionString, dragItemString, draggedOverString);
                }

                if (!forceUpdate && oldValue != m_dropTargetDropEffectString)
                {
                    AutomationPeer treePeer = FrameworkElementAutomationPeer.FromElement(this);
                    treePeer.RaisePropertyChangedEvent(DropTargetPatternIdentifiers.DropTargetEffectProperty, oldValue, m_dropTargetDropEffectString);
                }
            }
        }
Exemplo n.º 19
0
 protected override string GetHelpTextCore()
 {
     return(ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_HelpTextColorSpectrum));
 }
Exemplo n.º 20
0
 protected override string GetLocalizedControlTypeCore()
 {
     return(ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_LocalizedControlTypeColorSpectrum));
 }
Exemplo n.º 21
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var spinDownName = ResourceAccessor.GetLocalizedStringResource(SR_NumberBoxDownSpinButtonName);
            var spinUpName   = ResourceAccessor.GetLocalizedStringResource(SR_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();
            }
        }
Exemplo n.º 22
0
        protected override void OnApplyTemplate()
        {
            var popupRadius = (CornerRadius)ResourceAccessor.ResourceLookup(this, c_overlayCornerRadiusKey);

            var tabView         = SharedHelpers.GetAncestorOfType <TabView>(VisualTreeHelper.GetParent(this));
            var internalTabView = tabView ?? null;

            Button GetCloseButton(TabView internalTabView)
            {
                var closeButton = (Button)GetTemplateChild("CloseButton");

                if (closeButton != null)
                {
                    // Do localization for the close button automation name
                    if (string.IsNullOrEmpty(AutomationProperties.GetName(closeButton)))
                    {
                        var closeButtonName = ResourceAccessor.GetLocalizedStringResource(SR_TabViewCloseButtonName);
                        AutomationProperties.SetName(closeButton, closeButtonName);
                    }

                    if (internalTabView != null)
                    {
                        // Setup the tooltip for the close button
                        var tooltip = new ToolTip();
                        tooltip.Content = internalTabView.GetTabCloseButtonTooltipText();
                        ToolTipService.SetToolTip(closeButton, tooltip);
                    }

                    closeButton.Click += OnCloseButtonClick;
                }
                return(closeButton);
            }

            m_closeButton = GetCloseButton(internalTabView);

            OnIconSourceChanged();

            if (tabView != null)
            {
                if (SharedHelpers.IsThemeShadowAvailable())
                {
                    if (internalTabView != null)
                    {
                        var shadow = new ThemeShadow();
                        if (!SharedHelpers.Is21H1OrHigher())
                        {
                            if (internalTabView.GetShadowReceiver() is UIElement shadowReceiver)
                            {
                                shadow.Receivers.Add(shadowReceiver);
                            }
                        }
                        m_shadow = shadow;

                        double shadowDepth = (double)SharedHelpers.FindInApplicationResources(TabView.c_tabViewShadowDepthName, TabView.c_tabShadowDepth);

                        var currentTranslation = Translation;
                        var translation        = new Vector3(currentTranslation.X, currentTranslation.Y, (float)shadowDepth);
                        Translation = translation;

                        UpdateShadow();
                    }
                }

                tabView.TabDragStarting  += OnTabDragStarting;
                tabView.TabDragCompleted += OnTabDragCompleted;
            }

            UpdateCloseButton();
            UpdateWidthModeVisualState();
        }
Exemplo n.º 23
0
        private string GetToolTipString()
        {
            uint sliderValue = (uint)(Math.Round(this.Value));

            if (this.ColorChannel == ColorPickerHsvChannel.Alpha)
            {
                return(StringUtil.FormatString(
                           ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringAlphaSlider),
                           sliderValue));
            }
            else
            {
                ColorPicker parentColorPicker = GetParentColorPicker();
                if (parentColorPicker != null && DownlevelHelper.ToDisplayNameExists())
                {
                    Hsv    currentHsv = parentColorPicker.GetCurrentHsv();
                    string localizedString;

                    switch (this.ColorChannel)
                    {
                    case ColorPickerHsvChannel.Hue:
                        currentHsv.H    = this.Value;
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringHueSliderWithColorName);
                        break;

                    case ColorPickerHsvChannel.Saturation:
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringSaturationSliderWithColorName);
                        currentHsv.S    = this.Value / 100;
                        break;

                    case ColorPickerHsvChannel.Value:
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringValueSliderWithColorName);
                        currentHsv.V    = this.Value / 100;
                        break;

                    default:
                        throw new InvalidOperationException("Invalid ColorPickerHsvChannel.");                                 // Uno Doc: 'throw winrt::hresult_error(E_FAIL);'
                    }

                    return(StringUtil.FormatString(
                               localizedString,
                               sliderValue,
                               ColorHelper.ToDisplayName(ColorConversion.ColorFromRgba(ColorConversion.HsvToRgb(currentHsv)))));
                }
                else
                {
                    string localizedString;
                    switch (this.ColorChannel)
                    {
                    case ColorPickerHsvChannel.Hue:
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringHueSliderWithoutColorName);
                        break;

                    case ColorPickerHsvChannel.Saturation:
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringSaturationSliderWithoutColorName);
                        break;

                    case ColorPickerHsvChannel.Value:
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringValueSliderWithoutColorName);
                        break;

                    default:
                        throw new InvalidOperationException("Invalid ColorPickerHsvChannel.");                                 // Uno Doc: 'throw winrt::hresult_error(E_FAIL);'
                    }

                    return(StringUtil.FormatString(
                               localizedString,
                               sliderValue));
                }
            }
        }
Exemplo n.º 24
0
        protected override void OnApplyTemplate()
        {
            if (string.IsNullOrEmpty(PrefixText))
            {
                PrefixText = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlPrefixTextName);
            }
            if (string.IsNullOrEmpty(SuffixText))
            {
                SuffixText = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlSuffixTextName);
            }
            var rootGrid = GetTemplateChild <FrameworkElement>(c_rootGridName);

            if (rootGrid != null)
            {
                rootGrid.KeyDown += OnRootGridKeyDown;
                m_rootGridKeyDownRevoker.Disposable = Disposable.Create(() => rootGrid.KeyDown -= OnRootGridKeyDown);
            }

            var firstPageButton = GetTemplateChild <Button>(c_firstPageButtonName);

            if (firstPageButton != null)
            {
                AutomationProperties.SetName(firstPageButton, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlFirstPageButtonTextName));
                firstPageButton.Click += FirstButtonClicked;
                m_firstPageButtonClickRevoker.Disposable = Disposable.Create(() => firstPageButton.Click -= FirstButtonClicked);
            }
            var previousPageButton = GetTemplateChild <Button>(c_previousPageButtonName);

            if (previousPageButton != null)
            {
                AutomationProperties.SetName(previousPageButton, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlPreviousPageButtonTextName));
                previousPageButton.Click += PreviousButtonClicked;
                m_previousPageButtonClickRevoker.Disposable = Disposable.Create(() => previousPageButton.Click -= PreviousButtonClicked);
            }
            var nextPageButton = GetTemplateChild <Button>(c_nextPageButtonName);

            if (nextPageButton != null)
            {
                AutomationProperties.SetName(nextPageButton, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlNextPageButtonTextName));
                nextPageButton.Click += NextButtonClicked;
                m_nextPageButtonClickRevoker.Disposable = Disposable.Create(() => nextPageButton.Click -= NextButtonClicked);
            }
            var lastPageButton = GetTemplateChild <Button>(c_lastPageButtonName);

            if (lastPageButton != null)
            {
                AutomationProperties.SetName(lastPageButton, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlLastPageButtonTextName));
                lastPageButton.Click += LastButtonClicked;
                m_lastPageButtonClickRevoker.Disposable = Disposable.Create(() => lastPageButton.Click -= LastButtonClicked);
            }

            m_comboBoxSelectionChangedRevoker.Disposable = null;
            void InitComboBox(ComboBox comboBox)
            {
                m_comboBox = comboBox;
                if (comboBox != null)
                {
                    comboBox.SelectedIndex = SelectedPageIndex - 1;
                    AutomationProperties.SetName(comboBox, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlPageTextName));
                    comboBox.SelectionChanged += ComboBoxSelectionChanged;
                    m_comboBoxSelectionChangedRevoker.Disposable = Disposable.Create(() => comboBox.SelectionChanged -= ComboBoxSelectionChanged);
                }
            }

            InitComboBox((ComboBox)GetTemplateChild(c_comboBoxName));

            m_numberBoxValueChangedRevoker.Disposable = null;
            void InitNumberBox(NumberBox numberBox)
            {
                m_numberBox = numberBox;
                if (numberBox != null)
                {
                    numberBox.Value = SelectedPageIndex + 1;
                    AutomationProperties.SetName(numberBox, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlPageTextName));
                    numberBox.ValueChanged += NumberBoxValueChanged;
                    m_numberBoxValueChangedRevoker.Disposable = Disposable.Create(() => numberBox.ValueChanged -= NumberBoxValueChanged);
                }
            }

            InitNumberBox((NumberBox)GetTemplateChild(c_numberBoxName));

            m_numberPanelRepeater   = (ItemsRepeater)GetTemplateChild(c_numberPanelRepeaterName);
            m_selectedPageIndicator = (FrameworkElement)GetTemplateChild(c_numberPanelIndicatorName);

            // This is for the initial loading of the control
            OnDisplayModeChanged();
            UpdateOnEdgeButtonVisualStates();
            OnNumberOfPagesChanged(0);
            OnSelectedPageIndexChange(-1);
        }