Beispiel #1
0
        internal async Task UpdateToolbarItems()
        {
            var toolbarProvider = GetToolbarProvider();

            if (toolbarProvider == null)
            {
                return;
            }

            CommandBar commandBar = await toolbarProvider.GetCommandBarAsync();

            if (commandBar == null)
            {
                return;
            }

            commandBar.PrimaryCommands.Clear();
            commandBar.SecondaryCommands.Clear();

            var toolBarForegroundBinder = GetToolbarProvider() as IToolBarForegroundBinder;

            foreach (ToolbarItem item in _toolbarTracker.ToolbarItems)
            {
                toolBarForegroundBinder?.BindForegroundColor(commandBar);

                var button = new AppBarButton();
                button.SetBinding(AppBarButton.LabelProperty, "Text");

                if (commandBar.IsDynamicOverflowEnabled && item.Order == ToolbarItemOrder.Secondary)
                {
                    button.SetBinding(AppBarButton.IconProperty, "IconImageSource", _imageSourceIconElementConverter);
                }
                else
                {
                    var img = new WImage();
                    img.SetBinding(WImage.SourceProperty, "Value");
                    img.SetBinding(WImage.DataContextProperty, "IconImageSource", _imageConverter);
                    button.Content = img;
                }

                button.Command     = new MenuItemCommand(item);
                button.DataContext = item;
                button.SetValue(NativeAutomationProperties.AutomationIdProperty, item.AutomationId);
                button.SetAutomationPropertiesName(item);
                button.SetAutomationPropertiesAccessibilityView(item);
                button.SetAutomationPropertiesHelpText(item);
                button.SetAutomationPropertiesLabeledBy(item);

                ToolbarItemOrder order = item.Order == ToolbarItemOrder.Default ? ToolbarItemOrder.Primary : item.Order;
                if (order == ToolbarItemOrder.Primary)
                {
                    toolBarForegroundBinder?.BindForegroundColor(button);
                    commandBar.PrimaryCommands.Add(button);
                }
                else
                {
                    commandBar.SecondaryCommands.Add(button);
                }
            }
        }
Beispiel #2
0
        internal void UpdateMenu()
        {
            if (Handler.PlatformView is not MauiToolbar wh)
            {
                return;
            }

            var commandBar = wh.CommandBar;

            if (commandBar == null)
            {
                return;
            }

            commandBar.PrimaryCommands.Clear();
            commandBar.SecondaryCommands.Clear();

            List <ToolbarItem> toolbarItems = new List <ToolbarItem>(ToolbarItems ?? Array.Empty <ToolbarItem>());

            foreach (ToolbarItem item in toolbarItems)
            {
                var button = new AppBarButton();
                button.SetBinding(AppBarButton.LabelProperty, "Text");

                if (commandBar.IsDynamicOverflowEnabled && item.Order == ToolbarItemOrder.Secondary)
                {
                    button.SetBinding(AppBarButton.IconProperty, "IconImageSource", _imageSourceIconElementConverter);
                }
                else if (!item.IconImageSource.IsNullOrEmpty())
                {
                    var img = new WImage();
                    img.SetBinding(WImage.SourceProperty, "Value");
                    img.SetBinding(WImage.DataContextProperty, "IconImageSource", _imageConverter);
                    button.Content = img;
                }

                button.Command     = new MenuItemCommand(item);
                button.DataContext = item;
                button.SetValue(NativeAutomationProperties.AutomationIdProperty, item.AutomationId);
                button.SetAutomationPropertiesName(item);
                button.SetAutomationPropertiesAccessibilityView(item);
                button.SetAutomationPropertiesHelpText(item);
                button.UpdateTextColor(BarTextColor);

                button.SetAutomationPropertiesLabeledBy(item, null);

                ToolbarItemOrder order = item.Order == ToolbarItemOrder.Default ? ToolbarItemOrder.Primary : item.Order;
                if (order == ToolbarItemOrder.Primary)
                {
                    commandBar.PrimaryCommands.Add(button);
                }
                else
                {
                    commandBar.SecondaryCommands.Add(button);
                }
            }
        }
Beispiel #3
0
            public void Apply()
            {
                ReleaseItems();

                var all = _bar.PrimaryCommands
                          .Concat(_bar.SecondaryCommands)
                          .OfType <AppBarButton>()
                          .Where(x => x.DataContext != null)
                          .ToLookup(x => x.DataContext);

                _bar.PrimaryCommands.Clear();
                _bar.SecondaryCommands.Clear();

                foreach (var model in _source)
                {
                    var command = all[model]
                                  .FirstOrDefault();

                    if (command == null)
                    {
                        command = new AppBarButton
                        {
                            DataContext = model,
                        };

                        command.SetBinding(AppBarButton.LabelProperty,
                                           new Binding {
                            Path = new PropertyPath("Label")
                        });
                        command.SetBinding(AppBarButton.IconProperty,
                                           new Binding {
                            Path = new PropertyPath("Icon")
                        });
                        command.SetBinding(UIElement.VisibilityProperty,
                                           new Binding {
                            Path = new PropertyPath("Visibility")
                        });
                        command.SetBinding(Control.IsEnabledProperty,
                                           new Binding {
                            Path = new PropertyPath("IsEnabled")
                        });
                        Message.SetAttach(command, "Invoke()");
                    }

                    if (model.IsPrimary)
                    {
                        _bar.PrimaryCommands.Add(command);
                    }
                    else
                    {
                        _bar.SecondaryCommands.Add(command);
                    }
                }

                MonitorItems();
                UpdateAppBarVisibility();
            }
Beispiel #4
0
        internal async Task UpdateToolbarItems()
        {
            CommandBar commandBar = await GetCommandBarAsync();

            if (commandBar != null)
            {
                commandBar.PrimaryCommands.Clear();
                commandBar.SecondaryCommands.Clear();

                if (_page.BottomAppBar != null || _page.TopAppBar != null)
                {
                    _page.BottomAppBar = null;
                    _page.TopAppBar    = null;
                    _page.InvalidateMeasure();
                }
            }

            var toolBarProvider = GetToolbarProvider() as IToolBarForegroundBinder;

            foreach (ToolbarItem item in _toolbarTracker.ToolbarItems.OrderBy(ti => ti.Priority))
            {
                if (commandBar == null)
                {
                    commandBar = CreateCommandBar();
                }

                toolBarProvider?.BindForegroundColor(commandBar);

                var button = new AppBarButton();
                button.SetBinding(AppBarButton.LabelProperty, "Text");
                button.SetBinding(AppBarButton.IconProperty, "Icon", _fileImageSourcePathConverter);
                button.Command     = new MenuItemCommand(item);
                button.DataContext = item;

                ToolbarItemOrder order = item.Order == ToolbarItemOrder.Default ? ToolbarItemOrder.Primary : item.Order;
                if (order == ToolbarItemOrder.Primary)
                {
                    toolBarProvider?.BindForegroundColor(button);
                    commandBar.PrimaryCommands.Add(button);
                }
                else
                {
                    commandBar.SecondaryCommands.Add(button);
                }
            }

            if (commandBar?.PrimaryCommands.Count + commandBar?.SecondaryCommands.Count == 0)
            {
                ClearCommandBar();
            }
        }
Beispiel #5
0
        internal async Task UpdateToolbarItems()
        {
            var toolbarProvider = GetToolbarProvider();

            if (toolbarProvider == null)
            {
                return;
            }

            CommandBar commandBar = await toolbarProvider.GetCommandBarAsync();

            if (commandBar == null)
            {
                return;
            }

            commandBar.PrimaryCommands.Clear();
            commandBar.SecondaryCommands.Clear();

            var toolBarForegroundBinder = GetToolbarProvider() as IToolBarForegroundBinder;

            foreach (ToolbarItem item in _toolbarTracker.ToolbarItems.OrderBy(ti => ti.Priority))
            {
                toolBarForegroundBinder?.BindForegroundColor(commandBar);

                var button = new AppBarButton();
                button.SetBinding(AppBarButton.LabelProperty, "Text");
                button.SetBinding(AppBarButton.IconProperty, "Icon", _fileImageSourcePathConverter);
                button.Command     = new MenuItemCommand(item);
                button.DataContext = item;
                button.SetValue(NativeAutomationProperties.AutomationIdProperty, item.AutomationId);
                button.SetAutomationPropertiesName(item);
                button.SetAutomationPropertiesAccessibilityView(item);
                button.SetAutomationPropertiesHelpText(item);
                button.SetAutomationPropertiesLabeledBy(item);

                ToolbarItemOrder order = item.Order == ToolbarItemOrder.Default ? ToolbarItemOrder.Primary : item.Order;
                if (order == ToolbarItemOrder.Primary)
                {
                    toolBarForegroundBinder?.BindForegroundColor(button);
                    commandBar.PrimaryCommands.Add(button);
                }
                else
                {
                    commandBar.SecondaryCommands.Add(button);
                }
            }
        }
Beispiel #6
0
 virtual protected void SetTOC(BookItem b)
 {
     TOCData = new TOCSection(b);
     JumpMarkBtn.SetBinding(IsEnabledProperty, new Binding()
     {
         Source = TOCData, Path = new PropertyPath("AnchorAvailable")
     });
 }
Beispiel #7
0
        void BindViewModel()
        {
            var binding = new Binding {
                Path   = new PropertyPath("CloseCommand"),
                Source = ViewModel
            };

            _cancelButton.SetBinding(ButtonBase.CommandProperty, binding);
        }
Beispiel #8
0
        CommandBar AddOpenMasterButton(CommandBar commandBar)
        {
            if (!_toolbarTracker.HaveMasterDetail)
            {
                return(commandBar);
            }

            if (commandBar == null)
            {
                commandBar = CreateCommandBar();
            }

            Page target = _toolbarTracker.Target;
            var  mdp    = target as MasterDetailPage;

            while (mdp == null)
            {
                var container = target as IPageContainer <Page>;
                if (container == null)
                {
                    break;
                }

                target = container.CurrentPage;
                mdp    = container.CurrentPage as MasterDetailPage;
            }

            if (mdp == null || !mdp.ShouldShowToolbarButton())
            {
                return(commandBar);
            }

            var openMaster = new AppBarButton {
                DataContext = mdp
            };

            openMaster.SetBinding(AppBarButton.LabelProperty, "Master.Title");
            openMaster.SetBinding(AppBarButton.IconProperty, "Master.Icon", _fileImageSourcePathConverter);
            openMaster.Click += (s, a) => { mdp.IsPresented = !mdp.IsPresented; };

            commandBar.PrimaryCommands.Add(openMaster);

            return(commandBar);
        }
Beispiel #9
0
        internal async Task UpdateToolbarItems()
        {
            CommandBar commandBar = await GetCommandBarAsync();

            if (commandBar != null)
            {
                commandBar.PrimaryCommands.Clear();
                commandBar.SecondaryCommands.Clear();
            }

            commandBar = AddOpenMasterButton(commandBar);

            foreach (ToolbarItem item in _toolbarTracker.ToolbarItems.OrderBy(ti => ti.Priority))
            {
                if (commandBar == null)
                {
                    commandBar = CreateCommandBar();
                }

                var button = new AppBarButton();
                button.SetBinding(AppBarButton.LabelProperty, "Text");
                button.SetBinding(AppBarButton.IconProperty, "Icon", _fileImageSourcePathConverter);
                button.Command     = new MenuItemCommand(item);
                button.DataContext = item;

                ToolbarItemOrder order = item.Order == ToolbarItemOrder.Default ? ToolbarItemOrder.Primary : item.Order;
                if (order == ToolbarItemOrder.Primary)
                {
                    commandBar.PrimaryCommands.Add(button);
                }
                else
                {
                    commandBar.SecondaryCommands.Add(button);
                }
            }

            if (commandBar?.PrimaryCommands.Count + commandBar?.SecondaryCommands.Count == 0)
            {
                ClearCommandBar();
            }
        }
Beispiel #10
0
        /// <summary>
        /// Handles adding the database lock button to all child appbars.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
        {
            PassKeepPage newPage = ContentFrame.Content as PassKeepPage;

            DebugHelper.Assert(newPage != null);

            if (newPage.BottomAppBar == null)
            {
                newPage.BottomAppBar = new CommandBar();
            }

            CommandBar commandBar = newPage.BottomAppBar as CommandBar;

            DebugHelper.Assert(commandBar != null);

            AppBarButton lockButton = new AppBarButton
            {
                Label = this.lockButtonLabel,
                Icon  = new FontIcon
                {
                    FontFamily = new FontFamily("Segoe MDL2 Assets"),
                    Glyph      = "\uE1F6"
                }
            };

            lockButton.Click += LockAppBarButtonClick;

            Binding enabledBinding = new Binding
            {
                Source = ViewModel.PersistenceService,
                Path   = new PropertyPath("CanSave"),
                Mode   = BindingMode.OneWay
            };
            AppBarButton settingsButton = new AppBarButton
            {
                Label = this.settingsLabel,
                Icon  = new FontIcon
                {
                    FontFamily = new FontFamily("Segoe MDL2 Assets"),
                    Glyph      = "\uE115"
                }
            };

            settingsButton.Click += SettingsButtonClick;
            settingsButton.SetBinding(IsEnabledProperty, enabledBinding);

            AppBarButton masterKeyButton = new AppBarButton
            {
                Label = this.masterKeyLabel,
                Icon  = new FontIcon
                {
                    FontFamily = new FontFamily("Segoe MDL2 Assets"),
                    Glyph      = "\uE192"
                }
            };

            masterKeyButton.Click += MasterKeyButtonClick;
            masterKeyButton.SetBinding(IsEnabledProperty, enabledBinding);

            commandBar.SecondaryCommands.Add(lockButton);
            commandBar.SecondaryCommands.Add(settingsButton);
            commandBar.SecondaryCommands.Add(masterKeyButton);
        }
        /// <summary>
        /// Получить нижнюю строку команд.
        /// </summary>
        /// <returns>Строка команд.</returns>
        public AppBar GetBottomAppBar()
        {
            var appBar = new CommandBar();

            var syncButton = new AppBarButton()
            {
                Icon = new SymbolIcon(Symbol.Sync),
                Label = "Обновить"
            };
            syncButton.SetBinding(AppBarButton.IsEnabledProperty, new Binding() { Source = this, Path = new PropertyPath("ViewModel.Update.CanStart") });
            syncButton.Click += (sender, r) => ViewModel?.Update?.Start2(BoardCatalogUpdateMode.Load);

            return appBar;
        }
Beispiel #12
0
		CommandBar AddOpenMasterButton(CommandBar commandBar)
		{
			if (!_toolbarTracker.HaveMasterDetail)
			{
				return commandBar;
			}

			if (commandBar == null)
			{
				commandBar = CreateCommandBar();
			}

			Page target = _toolbarTracker.Target;
			var mdp = target as MasterDetailPage;
			while (mdp == null)
			{
				var container = target as IPageContainer<Page>;
				if (container == null)
				{
					break;
				}

				target = container.CurrentPage;
				mdp = container.CurrentPage as MasterDetailPage;
			}

			if (mdp == null || !mdp.ShouldShowToolbarButton())
			{
				return commandBar;
			}

			var openMaster = new AppBarButton { DataContext = mdp };
			openMaster.SetBinding(AppBarButton.LabelProperty, "Master.Title");
			openMaster.SetBinding(AppBarButton.IconProperty, "Master.Icon", _fileImageSourcePathConverter);
			openMaster.Click += (s, a) => { mdp.IsPresented = !mdp.IsPresented; };

			commandBar.PrimaryCommands.Add(openMaster);

			return commandBar;
		}
Beispiel #13
0
		internal async Task UpdateToolbarItems()
		{
			CommandBar commandBar = await GetCommandBarAsync();
			if (commandBar != null)
			{
				commandBar.PrimaryCommands.Clear();
				commandBar.SecondaryCommands.Clear();
#if WINDOWS_UWP
				if (_page.BottomAppBar != null || _page.TopAppBar != null)
				{
					_page.BottomAppBar = null;
					_page.TopAppBar = null;
					_page.InvalidateMeasure();
				}
#endif
			}

#if !WINDOWS_UWP
			commandBar = AddOpenMasterButton(commandBar);
#endif

#if WINDOWS_UWP
			var toolBarProvider = GetToolbarProvider() as IToolBarForegroundBinder;
#endif

			foreach (ToolbarItem item in _toolbarTracker.ToolbarItems.OrderBy(ti => ti.Priority))
			{
				if (commandBar == null)
					commandBar = CreateCommandBar();

#if WINDOWS_UWP
				toolBarProvider?.BindForegroundColor(commandBar);
#endif

				var button = new AppBarButton();
				button.SetBinding(AppBarButton.LabelProperty, "Text");
				button.SetBinding(AppBarButton.IconProperty, "Icon", _fileImageSourcePathConverter);
				button.Command = new MenuItemCommand(item);
				button.DataContext = item;

#if WINDOWS_UWP
				toolBarProvider?.BindForegroundColor(button);
#endif

				ToolbarItemOrder order = item.Order == ToolbarItemOrder.Default ? ToolbarItemOrder.Primary : item.Order;
				if (order == ToolbarItemOrder.Primary)
					commandBar.PrimaryCommands.Add(button);
				else
					commandBar.SecondaryCommands.Add(button);
			}

			if (commandBar?.PrimaryCommands.Count + commandBar?.SecondaryCommands.Count == 0)
				ClearCommandBar();
		}
Beispiel #14
0
        public AppBar GetBottomAppBar()
        {
            var appBar = new CommandBar();
            
            var syncButton = new AppBarButton()
            {
                Label = "Обновить",
                Icon = new SymbolIcon(Symbol.Sync),                
            };            
            syncButton.SetBinding(AppBarButton.IsEnabledProperty, new Binding() { Source = ViewModel, Path = new PropertyPath("CheckForUpdates.CanStart"), Mode = BindingMode.OneWay });
            syncButton.Click += (sender, e) => ViewModel.CheckForUpdates.Start();

            appBar.PrimaryCommands.Add(syncButton);

            return appBar;
        }
        /// <summary>
        /// Получить нижнюю строку команд.
        /// </summary>
        /// <returns>Строка команд.</returns>
        public AppBar GetBottomAppBar()
        {
            var appBar = new CommandBar();

            var postButton = new AppBarButton()
            {
                Icon = new SymbolIcon(Symbol.Edit),
                Label = "Написать"
            };
            postButton.Click += async (sender, e) =>
            {
                try
                {
                    var opPost = ViewModel?.OpPost;
                    if (opPost != null)
                    {
                        ServiceLocator.Current.GetServiceOrThrow<IPageNavigationService>().Navigate(new PostingNavigationTarget(opPost.ParentLink, opPost.Text) );
                    }
                }
                catch (Exception ex)
                {
                    await AppHelpers.ShowError(ex);
                }
            };

            var syncButton = new AppBarButton()
            {
                Icon = new SymbolIcon(Symbol.Sync),
                Label = "Обновить"
            };
            syncButton.SetBinding(AppBarButton.IsEnabledProperty, new Binding() { Source = this, Path = new PropertyPath("ViewModel.Update.CanStart") });
            syncButton.Click += (sender, e) => ViewModel?.Synchronize();

            appBar.PrimaryCommands.Add(postButton);

            if (currentContentView == PageContentViews.Default)
            {
                short downNum, upNum;
                unchecked
                {
                    downNum = (short)0xE74B;
                    upNum = (short)0xE74A;
                }

                var downButton = new AppBarButton()
                {
                    Icon = new FontIcon() { FontFamily = new FontFamily("Segoe MDL2 Assets"), Glyph = new string(new[] { (char)downNum }) },
                    Label = "Вниз"
                };
                downButton.Click += (sender, e) => Down();

                var upButton = new AppBarButton()
                {
                    Icon = new FontIcon() { FontFamily = new FontFamily("Segoe MDL2 Assets"), Glyph = new string(new[] { (char)upNum }) },
                    Label = "Вверх"
                };
                upButton.Click += (sender, e) => Up();

                appBar.PrimaryCommands.Add(upButton);
                appBar.PrimaryCommands.Add(downButton);
            } else if (currentContentView == PageContentViews.SinglePostView)
            {
                var backButton = new AppBarButton()
                {
                    Icon = new SymbolIcon(Symbol.Back),
                    Label = "Назад"
                };
                backButton.Click += (sender, e) => SingleListBack();

                var goButton = new AppBarButton()
                {
                    Icon = new SymbolIcon(Symbol.Go),
                    Label = "Перейти"
                };
                goButton.Click += (sender, e) => SingleListGo();
                appBar.PrimaryCommands.Add(backButton);
                appBar.PrimaryCommands.Add(goButton);
            }


            appBar.PrimaryCommands.Add(syncButton);

            var loadAllButton = new AppBarButton()
            {
                Label = "Загрузить заново",
            };
            loadAllButton.Click += (sender, e) =>
            {
                ViewModel?.FullReload();
            };

            var addToFavorites = new AppBarButton()
            {
                Label = "В избранное",
            };
            addToFavorites.Click += async (sender, e) =>
            {
                try
                {
                    var vm = ViewModel;
                    if (vm != null)
                    {
                        await vm.AddToFavorites();
                    }
                }
                catch (Exception ex)
                {
                    await AppHelpers.ShowError(ex);
                }
            };

            appBar.SecondaryCommands.Add(loadAllButton);
            appBar.SecondaryCommands.Add(addToFavorites);

            return appBar;
        }
Beispiel #16
0
        /// <summary>
        /// Получить нижнюю строку команд.
        /// </summary>
        /// <returns>Строка команд.</returns>
        public AppBar GetBottomAppBar()
        {
            var appBar = new CommandBar();

            var saveButton = new AppBarButton()
            {
                Label = "Сохранить",
                Icon = new SymbolIcon(Symbol.SaveLocal)
            };            
            saveButton.SetBinding(AppBarButton.IsEnabledProperty, new Binding() { Source = this, Path = new PropertyPath("IsLoaded"), Mode = BindingMode.OneWay});
            saveButton.Click += SaveButtonOnClick;

            var webButton = new AppBarButton()
            {
                Label = "Открыть в web",
                Icon = new SymbolIcon(Symbol.Globe)
            };
            webButton.Click += WebButtonOnClick;

            var appButton = new AppBarButton()
            {
                Label = "В программе",
                Icon = new SymbolIcon(Symbol.SlideShow)
            };
            appButton.SetBinding(AppBarButton.IsEnabledProperty, new Binding() { Source = this, Path = new PropertyPath("IsLoaded"), Mode = BindingMode.OneWay });
            appButton.Click += AppButtonOnClick;

            appBar.PrimaryCommands.Add(webButton);
            appBar.PrimaryCommands.Add(appButton);
            appBar.PrimaryCommands.Add(saveButton);

            return appBar;
        }
Beispiel #17
0
            public void Apply()
            {
                ReleaseItems();

                var all = _bar.PrimaryCommands
                    .Concat(_bar.SecondaryCommands)
                    .OfType<AppBarButton>()
                    .Where(x => x.DataContext != null)
                    .ToLookup(x => x.DataContext);

                _bar.PrimaryCommands.Clear();
                _bar.SecondaryCommands.Clear();

                foreach (var model in _source)
                {
                    var command = all[model]
                        .FirstOrDefault();

                    if (command == null)
                    {
                        command = new AppBarButton
                        {
                            DataContext = model,
                        };

                        command.SetBinding(AppBarButton.LabelProperty,
                            new Binding {Path = new PropertyPath("Label")});
                        command.SetBinding(AppBarButton.IconProperty,
                            new Binding {Path = new PropertyPath("Icon")});
                        command.SetBinding(UIElement.VisibilityProperty,
                            new Binding {Path = new PropertyPath("Visibility")});
                        command.SetBinding(Control.IsEnabledProperty,
                            new Binding {Path = new PropertyPath("IsEnabled")});
                        Message.SetAttach(command, "Invoke()");
                    }

                    if (model.IsPrimary)
                        _bar.PrimaryCommands.Add(command);
                    else
                        _bar.SecondaryCommands.Add(command);
                }

                MonitorItems();
                UpdateAppBarVisibility();
            }