Esempio n. 1
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var page = BindableApplicationBar.FindRootPage(this);

            if (page != null)
            {
                page.ApplicationBar = this.applicationBar;
            }

            if (!AreMenuItemsLoaded && this.MenuItems != null)
            {
                foreach (var item in this.MenuItems)
                {
                    var menuItem = GetMenuItem(this, item);
                    this.applicationBar.MenuItems.Add(menuItem);
                }
            }

            if (!AreButtonsLoaded && this.Buttons != null)
            {
                foreach (var button in this.Buttons)
                {
                    var bindableButton = button as BindableApplicationBarIconButton;
                    if (bindableButton != null)
                    {
                        bindableButton.DataContext = this.DataContext;
                    }
                }
            }
        }
Esempio n. 2
0
        private static object GetButton(BindableApplicationBar bindableApplicationBar, object item)
        {
            var bindableButton = item as BindableApplicationBarIconButton;

            if (bindableButton != null)
            {
                bindableButton.DataContext = bindableApplicationBar.DataContext;
                bindableButton.DataItem    = item;
                if (!string.IsNullOrEmpty(bindableApplicationBar.MenuItemClickMethodName))
                {
                    bindableButton.ClickMethodName = bindableApplicationBar.MenuItemClickMethodName;
                }
                return(bindableButton);
            }
            else if (item is ApplicationBarMenuItem)
            {
                return(item);
            }
            else
            {
                var textProperty = item.GetType().GetProperty(bindableApplicationBar.TextMemberPath);
                var menuItem     = new BindableApplicationBarMenuItem();
                menuItem.Text            = textProperty.GetValue(item).ToString();
                menuItem.DataContext     = bindableApplicationBar.DataContext;
                menuItem.ClickMethodName = bindableApplicationBar.MenuItemClickMethodName;
                menuItem.DataItem        = item;
                return(menuItem);
            }
        }
Esempio n. 3
0
 private static object GetMenuItem(BindableApplicationBar bindableApplicationBar, object item)
 {
     var bindableMenuItem = item as BindableApplicationBarMenuItem;
     if (bindableMenuItem != null)
     {
         bindableMenuItem.DataContext = bindableApplicationBar.DataContext;
         bindableMenuItem.DataItem = item;
         if (!string.IsNullOrEmpty(bindableApplicationBar.MenuItemClickMethodName))
         {
             bindableMenuItem.ClickMethodName = bindableApplicationBar.MenuItemClickMethodName;
         }
         return bindableMenuItem;
     }
     else if (item is ApplicationBarMenuItem)
     {
         return item;
     }
     else
     {
         var textProperty = item.GetType().GetProperty(bindableApplicationBar.TextMemberPath);
         var menuItem = new BindableApplicationBarMenuItem();
         menuItem.Text = textProperty.GetValue(item).ToString();
         menuItem.DataContext = bindableApplicationBar.DataContext;
         menuItem.ClickMethodName = bindableApplicationBar.MenuItemClickMethodName;
         menuItem.DataItem = item;
         return menuItem;
     }
 }