public void BindApplicationBar(IApplicationBarViewModel viewModel) { if (viewModel == null) { return; } if (this.Page == null || this.Page.ApplicationBar == null) { return; } if (this.Page.ApplicationBar.IsMenuEnabled) { var appBarViewModel = (IApplicationBarViewModel)viewModel; this.RefreshButtons(appBarViewModel); this.appBarSubscriptions.Add( Observable.FromEvent <NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>( handler => new NotifyCollectionChangedEventHandler(handler), handler => appBarViewModel.ApplicationBarButtonCommands.CollectionChanged += handler, handler => appBarViewModel.ApplicationBarButtonCommands.CollectionChanged -= handler). ObserveOnDispatcher().Subscribe(_ => this.RefreshButtons(appBarViewModel))); this.RefreshMenuItems(appBarViewModel); this.appBarSubscriptions.Add( Observable.FromEvent <NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>( handler => new NotifyCollectionChangedEventHandler(handler), handler => appBarViewModel.ApplicationBarMenuCommands.CollectionChanged += handler, handler => appBarViewModel.ApplicationBarMenuCommands.CollectionChanged -= handler). ObserveOnDispatcher().Subscribe(_ => this.RefreshMenuItems(appBarViewModel))); } }
private void RefreshButtons(IApplicationBarViewModel viewModel) { if (this.Page == null || this.Page.ApplicationBar == null) { return; } this.Page.ApplicationBar.Buttons.Clear(); foreach (var commandLink in viewModel.ApplicationBarButtonCommands) { this.AddApplicationBarButton(commandLink); } }
private void RefreshMenuItems(IApplicationBarViewModel appBarViewModel) { if (this.Page == null || this.Page.ApplicationBar == null) { return; } this.Page.ApplicationBar.MenuItems.Clear(); foreach (var commandLink in appBarViewModel.ApplicationBarMenuCommands) { this.AddApplicationBarMenu(commandLink); } }
/// <summary> /// Initializes a new instance of the ApplicationBarBinder class. /// </summary> public ApplicationBarBinder(PhoneApplicationPage page, IApplicationBarViewModel viewModel) : this(page) { this.BindApplicationBar(viewModel); }