private List <CommandBarButtonItem> CheckForToolbarItems(object view) { var buttonList = new List <CommandBarButtonItem>(); var members = GetMethods(view); foreach (var member in members) { var toolbarButtonAttribute = member.GetCustomAttribute <ToolbarButtonAttribute>(false); var captionAttribute = member.GetCustomAttribute <CaptionAttribute>(); var caption = captionAttribute != null ? captionAttribute.Caption : null; if (toolbarButtonAttribute != null) { var title = caption ?? toolbarButtonAttribute.Title; ICommand command = null; var methodInfo = member as MethodInfo; if (methodInfo != null) { command = new ReflectiveCommand(view, member as MethodInfo, null); } CommandBarButtonItem button = null; if (!string.IsNullOrEmpty(title)) { button = new CommandBarButtonItem(title, toolbarButtonAttribute.Style, delegate { command.Execute(null); }); } else { button = new CommandBarButtonItem(toolbarButtonAttribute.ButtonType, delegate { command.Execute(null); }); button.Style = toolbarButtonAttribute.Style; } button.Enabled = true; button.Location = toolbarButtonAttribute.Location; var orderAttribute = member.GetCustomAttribute <OrderAttribute>(); if (orderAttribute != null) { button.Order = orderAttribute.Order; } else { button.Order = 0; } buttonList.Add(button); } } if (buttonList.Count > 0) { var sortedList = buttonList.OrderBy(button => button.Tag).ToList(); return(sortedList); } return(null); }
private CommandBarButtonItem CreateCommandBarButton(object view, MemberInfo member, string title, UIView buttonView, UIBarButtonItemStyle style, UIBarButtonSystemItem buttonType, BarButtonLocation location) { CommandBarButtonItem button = null; ICommand command = null; var methodInfo = member as MethodInfo; if (methodInfo != null) { command = new ReflectiveCommand(view, member as MethodInfo, null); } if (!string.IsNullOrEmpty(title)) { button = new CommandBarButtonItem(title, style, delegate { command.Execute(null); }); } else if (buttonView != null) { button = new CommandBarButtonItem(buttonView); } else { button = new CommandBarButtonItem(buttonType, delegate { command.Execute(null); }); button.Style = style; } button.Enabled = true; button.Location = location; var orderAttribute = member.GetCustomAttribute <OrderAttribute>(); if (orderAttribute != null) { button.Order = orderAttribute.Order; } else { button.Order = 0; } return(button); }
private CommandBarButtonItem CreateCommandBarButton(object view, MemberInfo member, string title, UIBarButtonItemStyle style, UIBarButtonSystemItem buttonType, BarButtonLocation location ) { CommandBarButtonItem button = null; ICommand command = null; var methodInfo = member as MethodInfo; if(methodInfo != null) command = new ReflectiveCommand(view, member as MethodInfo, null); if(!string.IsNullOrEmpty(title)) { button = new CommandBarButtonItem(title, style, delegate {command.Execute(null); }); } else { button = new CommandBarButtonItem(buttonType, delegate {command.Execute(null); }); button.Style = style; } button.Enabled = true; button.Location = location; var orderAttribute = member.GetCustomAttribute<OrderAttribute>(); if (orderAttribute != null) button.Order = orderAttribute.Order; else button.Order = 0; return button; }
private List<CommandBarButtonItem> CheckForNavbarItems(object view) { var buttonList = new List<CommandBarButtonItem>(); var members = GetMethods(view); foreach(var member in members) { var navbarButtonAttribute = member.GetCustomAttribute<NavbarButtonAttribute>(false); var captionAttribute = member.GetCustomAttribute<CaptionAttribute>(); var caption = captionAttribute != null ? captionAttribute.Caption : null; if (navbarButtonAttribute != null) { var title = caption ?? navbarButtonAttribute.Title; ICommand command = null; var methodInfo = member as MethodInfo; if(methodInfo != null) command = new ReflectiveCommand(view, member as MethodInfo, null); CommandBarButtonItem button = null; if(!string.IsNullOrEmpty(title)) { button = new CommandBarButtonItem(title, navbarButtonAttribute.Style, delegate {command.Execute(null); }); } else { button = new CommandBarButtonItem(navbarButtonAttribute.ButtonType, delegate {command.Execute(null); }); button.Style = navbarButtonAttribute.Style; } button.Enabled = true; button.Location = navbarButtonAttribute.Location; var orderAttribute = member.GetCustomAttribute<OrderAttribute>(); if (orderAttribute != null) button.Order = orderAttribute.Order; else button.Order = 0; buttonList.Add(button); } } if (buttonList.Count > 0) { var sortedList = buttonList.OrderBy(button=>button.Tag).ToList(); return sortedList; } return null; }