public void Apply(IMenu menu, Context context, object parent) { PlatformExtensions.ValidateTemplate(ItemsSource, Items); var setter = new XmlPropertySetter <MenuTemplate, IMenu>(menu, context, new BindingSet()); BindingExtensions.AttachedParentMember.SetValue(menu, parent); setter.SetBinding(template => template.DataContext, DataContext, false); setter.SetBoolProperty(template => template.IsVisible, IsVisible); setter.SetBoolProperty(template => template.IsEnabled, IsEnabled); if (string.IsNullOrEmpty(ItemsSource)) { if (Items != null) { for (int index = 0; index < Items.Count; index++) { Items[index].Apply(menu, context, index, index); } } } else { MenuItemsSourceGenerator.Set(menu, context, ItemTemplate); setter.SetBinding(template => template.ItemsSource, ItemsSource, true); } setter.Apply(); }
private void ApplyInternal(IMenu menu, Context context, int id, int order, object dataContext, bool useContext) { PlatformExtensions.ValidateTemplate(ItemsSource, Items); bool isSubMenu = !string.IsNullOrEmpty(ItemsSource) || (Items != null && Items.Count > 0); XmlPropertySetter <MenuItemTemplate, IMenuItem> setter; if (isSubMenu) { ISubMenu subMenu = menu.AddSubMenu(0, id, order, string.Empty); setter = new XmlPropertySetter <MenuItemTemplate, IMenuItem>(subMenu.Item, context, new BindingSet()); BindingExtensions.AttachedParentMember.SetValue(subMenu, menu); BindingExtensions.AttachedParentMember.SetValue(subMenu.Item, subMenu); SetDataContext(subMenu, setter.BindingSet, 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 { MenuItemsSourceGenerator.Set(subMenu, context, ItemTemplate ?? this); XmlPropertySetter <object, object> .AddBinding(setter.BindingSet, subMenu, AttachedMemberConstants.ItemsSource, ItemsSource, true); } } else { var menuItem = menu.Add(0, id, order, string.Empty); setter = new XmlPropertySetter <MenuItemTemplate, IMenuItem>(menuItem, context, new BindingSet()); BindingExtensions.AttachedParentMember.SetValue(menuItem, menu); SetDataContext(menuItem, setter.BindingSet, dataContext, useContext); ApplySelf(menuItem, setter); } setter.Apply(); }