示例#1
0
        void UpdateBottomBar()
        {
            _BottomBar.Children.Clear();
            _BottomBar.ColumnDefinitions.Clear();
            var items = ShellItemController?.GetItems();

            if (items?.Count > 1)
            {
                for (int i = 0; i < items.Count; i++)
                {
                    var section = items[i];
                    var btn     = new AppBarButton()
                    {
                        Label    = section.Title,
                        Width    = double.NaN,
                        MinWidth = 68,
                        MaxWidth = 200
                    };

                    switch (section.Icon)
                    {
                    case FileImageSource fileImageSource:
                        btn.Icon = new BitmapIcon()
                        {
                            UriSource = new Uri("ms-appx:///" + fileImageSource.File)
                        };
                        break;

                    case FontImageSource fontImageSource:

                        var icon = new FontIcon()
                        {
                            Glyph      = fontImageSource.Glyph,
                            FontFamily = new FontFamily(fontImageSource.FontFamily),
                            FontSize   = fontImageSource.Size,
                        };

                        if (!fontImageSource.Color.IsDefault)
                        {
                            icon.Foreground = fontImageSource.Color.ToBrush();
                        }

                        btn.Icon = icon;
                        break;
                    }

                    btn.Click += (s, e) => OnShellSectionClicked(section);
                    _BottomBar.ColumnDefinitions.Add(new UwpColumnDefinition()
                    {
                        Width = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Star)
                    });
                    SetColumn(btn, i);
                    _BottomBar.Children.Add(btn);
                }
            }
        }
示例#2
0
        public ShellItemRenderer(ShellRenderer shellContext)
        {
            Xamarin.Forms.Shell.VerifyShellUWPFlagEnabled(nameof(ShellItemRenderer));
            _ = shellContext ?? throw new ArgumentNullException(nameof(shellContext));

            ShellContext = shellContext;
            RowDefinitions.Add(new UwpRowDefinition()
            {
                Height = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Auto)
            });
            RowDefinitions.Add(new UwpRowDefinition()
            {
                Height = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Star)
            });
            RowDefinitions.Add(new UwpRowDefinition()
            {
                Height = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Auto)
            });

            _Title = new TextBlock()
            {
                Style             = Resources["SubtitleTextBlockStyle"] as UwpStyle,
                VerticalAlignment = VerticalAlignment.Center,
                TextTrimming      = TextTrimming.CharacterEllipsis,
                TextWrapping      = TextWrapping.NoWrap
            };
            _HeaderArea = new UwpGrid()
            {
                Height = 40, Padding = WinUIHelpers.CreateThickness(10, 0, 10, 0)
            };
            _HeaderArea.ColumnDefinitions.Add(new UwpColumnDefinition()
            {
                Width = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Star)
            });
            _HeaderArea.ColumnDefinitions.Add(new UwpColumnDefinition()
            {
                Width = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Auto)
            });
            _HeaderArea.Children.Add(_Title);
            Children.Add(_HeaderArea);

            _Toolbar = new ItemsControl()
            {
                ItemTemplate = UwpApplication.Current.Resources["ShellToolbarItemTemplate"] as UwpDataTemplate,
                ItemsPanel   = UwpApplication.Current.Resources["ShellToolbarItemsPanelTemplate"] as ItemsPanelTemplate,
            };
            SetColumn(_Toolbar, 1);
            _HeaderArea.Children.Add(_Toolbar);

            SectionRenderer = shellContext.CreateShellSectionRenderer();
            SetRow(SectionRenderer, 1);

            Children.Add(SectionRenderer);

            _BottomBar = new UwpGrid()
            {
                HorizontalAlignment = HorizontalAlignment.Center
            };
            _BottomBarArea = new Border()
            {
                Child = _BottomBar
            };
            SetRow(_BottomBarArea, 2);
            Children.Add(_BottomBarArea);
        }