Exemplo n.º 1
0
        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)));
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the ApplicationBarBinder class.
 /// </summary>
 public ApplicationBarBinder(PhoneApplicationPage page, IApplicationBarViewModel viewModel)
     : this(page)
 {
     this.BindApplicationBar(viewModel);
 }