Exemple #1
0
        public virtual HorizontalAlignment Parse(Windows.UI.Xaml.HorizontalAlignment horizontalAlignment)
        {
            switch (horizontalAlignment)
            {
            case Windows.UI.Xaml.HorizontalAlignment.Left:
                return(HorizontalAlignment.Left);

            case Windows.UI.Xaml.HorizontalAlignment.Center:
                return(HorizontalAlignment.Center);

            case Windows.UI.Xaml.HorizontalAlignment.Right:
                return(HorizontalAlignment.Right);

            case Windows.UI.Xaml.HorizontalAlignment.Stretch:
                return(HorizontalAlignment.Fill);
            }

            throw new ArgumentOutOfRangeException("horizontalAlignment");
        }
Exemple #2
0
        void UpdateBarIcons()
        {
            if (Control == null || Element == null)
            {
                return;
            }

            if (!Element.IsSet(Specifics.HeaderIconsEnabledProperty))
            {
                return;
            }

            bool headerIconsEnabled = Element.OnThisPlatform().GetHeaderIconsEnabled();
            bool invalidateMeasure  = false;

            // Get all stack panels affected by update.
            var stackPanels = Control.GetDescendantsByName <WStackPanel>(TabBarHeaderStackPanelName);

            foreach (var stackPanel in stackPanels)
            {
                int stackPanelChildCount = stackPanel.Children.Count;
                for (int i = 0; i < stackPanelChildCount; i++)
                {
                    var stackPanelItem = stackPanel.Children[i];
                    if (stackPanelItem is WImage tabBarImage)
                    {
                        // Update icon image.
                        if (tabBarImage.GetValue(FrameworkElement.NameProperty).ToString() == TabBarHeaderImageName)
                        {
                            if (headerIconsEnabled)
                            {
                                if (Element.IsSet(Specifics.HeaderIconsSizeProperty))
                                {
                                    Size iconSize = Element.OnThisPlatform().GetHeaderIconsSize();
                                    tabBarImage.Height = iconSize.Height;
                                    tabBarImage.Width  = iconSize.Width;
                                }
                                tabBarImage.HorizontalAlignment = WHorizontalAlignment.Center;
                                tabBarImage.Visibility          = WVisibility.Visible;
                            }
                            else
                            {
                                tabBarImage.Visibility = WVisibility.Collapsed;
                            }

                            invalidateMeasure = true;
                        }
                    }
                    else if (stackPanelItem is WTextBlock tabBarTextblock)
                    {
                        // Update text block.
                        if (tabBarTextblock.GetValue(FrameworkElement.NameProperty).ToString() == TabBarHeaderTextBlockName)
                        {
                            if (headerIconsEnabled)
                            {
                                // Remember old values so we can restore them if icons are collapsed.
                                // NOTE, since all Textblock instances in this stack panel comes from the same
                                // style, we just keep one copy of the value (since they should be identical).
                                if (tabBarTextblock.TextAlignment != WTextAlignment.Center)
                                {
                                    _oldBarTextBlockTextAlignment = tabBarTextblock.TextAlignment;
                                    tabBarTextblock.TextAlignment = WTextAlignment.Center;
                                }

                                if (tabBarTextblock.HorizontalAlignment != WHorizontalAlignment.Center)
                                {
                                    _oldBarTextBlockHorinzontalAlignment = tabBarTextblock.HorizontalAlignment;
                                    tabBarTextblock.HorizontalAlignment  = WHorizontalAlignment.Center;
                                }
                            }
                            else
                            {
                                // Restore old values.
                                tabBarTextblock.TextAlignment       = _oldBarTextBlockTextAlignment;
                                tabBarTextblock.HorizontalAlignment = _oldBarTextBlockHorinzontalAlignment;
                            }
                        }
                    }
                }
            }

            // If items have been made visible or collapsed in panel, invalidate current control measures.
            if (invalidateMeasure)
            {
                Control.InvalidateMeasure();
            }
        }