Beispiel #1
0
        void UpdateToolbar()
        {
            Control.PrimaryTopBarCommands.Clear();
            Control.SecondaryTopBarCommands.Clear();

            foreach (var item in Element.ToolbarItems)
            {
                var appBar = new FormsAppBarButton()
                {
                    DataContext = item
                };

                var iconBinding = new System.Windows.Data.Binding(nameof(item.IconImageSource))
                {
                    Converter = new IconConveter()
                };

                appBar.SetBinding(FormsAppBarButton.IconProperty, iconBinding);
                appBar.SetBinding(FormsAppBarButton.LabelProperty, nameof(item.Text));
                appBar.SetBinding(FormsAppBarButton.IsEnabledProperty, nameof(item.IsEnabled));
                appBar.SetValue(FrameworkElementAttached.PriorityProperty, item.Priority);

                appBar.Click += (sender, e) =>
                {
                    if (appBar.DataContext is ToolbarItem toolbarItem)
                    {
                        ((IMenuItemController)toolbarItem).Activate();
                    }
                };

                if (item.Order == ToolbarItemOrder.Default || item.Order == ToolbarItemOrder.Primary)
                {
                    Control.PrimaryTopBarCommands.Add(appBar);
                }
                else
                {
                    Control.SecondaryTopBarCommands.Add(appBar);
                }
            }
        }
Beispiel #2
0
        void UpdateToolbar()
        {
            Control.PrimaryTopBarCommands.Clear();
            Control.SecondaryTopBarCommands.Clear();

            foreach (var item in Element.ToolbarItems)
            {
                FormsAppBarButton appBar = new FormsAppBarButton()
                {
                    Label = item.Text,
                    Tag   = item
                };

                appBar.SetValue(FrameworkElementAttached.PriorityProperty, item.Priority);

                if (item.Icon != null)
                {
                    Symbol   symbol;
                    Geometry geometry;

                    if (Enum.TryParse(item.Icon.File, true, out symbol))
                    {
                        appBar.Icon = new FormsSymbolIcon()
                        {
                            Symbol = symbol
                        }
                    }
                    ;
                    else if (TryParseGeometry(item.Icon.File, out geometry))
                    {
                        appBar.Icon = new FormsPathIcon()
                        {
                            Data = geometry
                        }
                    }
                    ;
                    else if (Path.GetExtension(item.Icon.File) != null)
                    {
                        appBar.Icon = new FormsBitmapIcon()
                        {
                            UriSource = new Uri(item.Icon.File, UriKind.RelativeOrAbsolute)
                        }
                    }
                    ;
                }

                appBar.Click += (sender, e) =>
                {
                    if (appBar.Tag != null && appBar.Tag is ToolbarItem)
                    {
                        (appBar.Tag as ToolbarItem).Activate();
                    }
                };

                if (item.Order == ToolbarItemOrder.Default || item.Order == ToolbarItemOrder.Primary)
                {
                    Control.PrimaryTopBarCommands.Add(appBar);
                }
                else
                {
                    Control.SecondaryTopBarCommands.Add(appBar);
                }
            }
        }