public void Apply(IMenu menu, Context context, object parent) { AndroidToolkitExtensions.ValidateTemplate(ItemsSource, Items); var setter = new XmlPropertySetter(menu, context); menu.SetBindingMemberValue(AttachedMembers.Object.Parent, parent); setter.SetBinding(nameof(DataContext), DataContext, false); setter.SetBoolProperty(nameof(IsVisible), IsVisible); setter.SetBoolProperty(nameof(IsEnabled), IsEnabled); if (!string.IsNullOrEmpty(Bind)) { setter.Bind(menu, Bind); } if (string.IsNullOrEmpty(ItemsSource)) { if (Items != null) { for (int index = 0; index < Items.Count; index++) { Items[index].Apply(menu, context, index, index); } } } else { menu.SetBindingMemberValue(AttachedMembers.Menu.ItemsSourceGenerator, new MenuItemsSourceGenerator(menu, context, ItemTemplate)); setter.SetBinding(nameof(ItemsSource), ItemsSource, true); } setter.Apply(); }
private void ApplyInternal(IMenu menu, Context context, int id, int order, object dataContext, bool useContext) { AndroidToolkitExtensions.ValidateTemplate(ItemsSource, Items); bool isSubMenu = !string.IsNullOrEmpty(ItemsSource) || Items != null && Items.Count > 0; XmlPropertySetter setter; int groupId; int.TryParse(Group, out groupId); if (isSubMenu) { ISubMenu subMenu = menu.AddSubMenu(groupId, id, order, string.Empty); setter = new XmlPropertySetter(subMenu.Item, context); subMenu.SetBindingMemberValue(AttachedMembers.Object.Parent, menu); subMenu.Item.SetBindingMemberValue(AttachedMembers.Object.Parent, subMenu); SetDataContext(subMenu, setter, dataContext, useContext); ApplySelf(subMenu.Item, setter); if (string.IsNullOrEmpty(ItemsSource)) { for (int index = 0; index < Items.Count; index++) { Items[index].Apply(subMenu, context, index, index); } } else { subMenu.SetBindingMemberValue(AttachedMembers.Menu.ItemsSourceGenerator, new MenuItemsSourceGenerator(subMenu, context, ItemTemplate ?? this)); XmlPropertySetter.AddBinding(setter, subMenu, AttachedMemberConstants.ItemsSource, ItemsSource, true); } } else { var menuItem = menu.Add(groupId, id, order, string.Empty); setter = new XmlPropertySetter(menuItem, context); menuItem.SetBindingMemberValue(AttachedMembers.Object.Parent, menu); SetDataContext(menuItem, setter, dataContext, useContext); ApplySelf(menuItem, setter); } setter.Apply(); }
public void Apply(Activity activity) { AndroidToolkitExtensions.ValidateTemplate(ItemsSource, Items); var actionBar = activity.GetActionBar(); var setter = new XmlPropertySetter(actionBar, activity); setter.SetEnumProperty <ActionBarNavigationMode>(nameof(NavigationMode), NavigationMode); setter.SetProperty(nameof(DataContext), DataContext); if (!string.IsNullOrEmpty(Bind)) { setter.Bind(actionBar, Bind); } setter.SetProperty(nameof(ContextActionBarTemplate), ContextActionBarTemplate); setter.SetBinding(nameof(ContextActionBarVisible), ContextActionBarVisible, false); setter.SetProperty(nameof(BackgroundDrawable), BackgroundDrawable); setter.SetProperty(nameof(CustomView), CustomView); setter.SetEnumProperty <ActionBarDisplayOptions>(nameof(DisplayOptions), DisplayOptions); setter.SetBoolProperty(nameof(DisplayHomeAsUpEnabled), DisplayHomeAsUpEnabled); setter.SetBoolProperty(nameof(DisplayShowCustomEnabled), DisplayShowCustomEnabled); setter.SetBoolProperty(nameof(DisplayShowHomeEnabled), DisplayShowHomeEnabled); setter.SetBoolProperty(nameof(DisplayShowTitleEnabled), DisplayShowTitleEnabled); setter.SetBoolProperty(nameof(DisplayUseLogoEnabled), DisplayUseLogoEnabled); setter.SetBoolProperty(nameof(HomeButtonEnabled), HomeButtonEnabled); setter.SetProperty(nameof(Icon), Icon); setter.SetProperty(nameof(Logo), Logo); setter.SetProperty(nameof(SplitBackgroundDrawable), SplitBackgroundDrawable); setter.SetProperty(nameof(StackedBackgroundDrawable), StackedBackgroundDrawable); setter.SetBoolProperty(nameof(IsShowing), IsShowing); setter.SetStringProperty(nameof(Subtitle), Subtitle); setter.SetStringProperty(nameof(Title), Title); setter.SetBoolProperty(nameof(Visible), Visible); setter.SetBinding(AttachedMembers.ActionBar.HomeButtonClick, HomeButtonClick, false); if (string.IsNullOrEmpty(ItemsSource)) { if (Items != null) { ActionBar.Tab firstTab = null; for (int index = 0; index < Items.Count; index++) { var tab = Items[index].CreateTab(actionBar); if (firstTab == null) { firstTab = tab; } actionBar.AddTab(tab); } TryRestoreSelectedIndex(activity, actionBar); } } else { #if APPCOMPAT actionBar.SetBindingMemberValue(AttachedMembersCompat.ActionBar.ItemsSourceGenerator, new ActionBarTabItemsSourceGenerator(actionBar, TabTemplate)); #else actionBar.SetBindingMemberValue(AttachedMembers.ActionBar.ItemsSourceGenerator, new ActionBarTabItemsSourceGenerator(actionBar, TabTemplate)); #endif setter.SetBinding(nameof(ItemsSource), ItemsSource, false); } setter.SetBinding(nameof(SelectedItem), SelectedItem, false); setter.Apply(); }