public void Add(Button button) { if (button == null) return; Buttons.Add (button); }
private RootElement RenderEditItem(Item item, bool renderListInfo) { // get itemType for this item ItemType itemType = null; try { itemType = App.ViewModel.ItemTypes.Single(it => it.ID == item.ItemTypeID); } catch (Exception) { // if can't find the folder type, use the first itemType = App.ViewModel.ItemTypes[0]; } // render the primary fields Section primarySection = RenderEditItemFields(item, itemType, true); // HACK: insert a dummy element inside the primary section. This dummy element // implements IElementSizing and returns a 0-sized cell (so it is invisible). // This is to work around an issue in MT.Dialog where it doesn't honor IElementSizing // on elements that are added after a dialog is already drawn. This element must be // inserted after the first element but before the last element, to avoid losing the // rounded rectangle look of the first and last elements of a Section. if (primarySection.Count > 0) primarySection.Insert(1, new DummyElement()); // render more button var moreButton = new Button() { Background = "Images/darkgreybutton.png", Caption = "more details" }; var sse = new ButtonListElement() { Margin = 0f }; sse.Buttons.Add(moreButton); var moreSection = new Section() { sse }; // render save/delete buttons var actionButtons = new ButtonListElement() { //new Button() { Caption = "Save", Background = "Images/greenbutton.png", Clicked = SaveButton_Click }, new Button() { Caption = "Delete", Background = "Images/redbutton.png", Clicked = DeleteButton_Click }, }; actionButtons.Margin = 0f; // create the dialog with the primary section RootElement editRoot = new RootElement(item.Name) { primarySection, moreSection, new Section() { actionButtons }, }; moreButton.Clicked += (s, e) => { // remove the "more" button editRoot.Remove(moreSection); // render the non-primary fields as a new section editRoot.Insert(1, RenderEditItemFields(item, itemType, false)); // create a separate section with the advanced information (parent, type) var advancedSection = new Section(); Field field = new Field() { Name = "ParentID", DisplayName = "List", DisplayType = DisplayTypes.Lists }; advancedSection.Add(RenderEditItemField(item, field)); field = new Field() { Name = "ItemTypeID", DisplayName = "Type", DisplayType = DisplayTypes.ItemTypes }; advancedSection.Add(RenderEditItemField(item, field)); editRoot.Insert(2, advancedSection); }; return editRoot; }
private UIBarButtonItem CreateSortButton() { // if haven't loaded the sort image yet, do so now if (sortButtonImage == null) sortButtonImage = UIImageCache.GetUIImage("Images/appbar.sort.rest.png"); // clicking the sort button and its event handler, which creates a new DialogViewController to host the sort picker var sortButton = new UIBarButtonItem(sortButtonImage, UIBarButtonItemStyle.Plain, delegate { // create the remove button var removeButton = new Button() { Caption = "Remove Sort", Background = "Images/darkgreybutton.png", }; var removeButtonList = new ButtonListElement() { removeButton }; removeButtonList.Margin = 0f; // find the current sort field if any var itemType = App.ViewModel.ItemTypes.Single(it => it.ID == Source.List.ItemTypeID); var fields = itemType.Fields.Where(f => f.IsPrimary == true).ToList(); var selectedSortIndex = 0; if (Source.OrderBy != null && fields.Any(f => f.DisplayName == Source.OrderBy)) { var selectedSortField = fields.Single(f => f.DisplayName == Source.OrderBy); selectedSortIndex = Math.Max(fields.IndexOf(selectedSortField), 0); } // create the sort picker var sortPickerSection = new Section(); sortPickerSection.AddAll(from f in fields select (Element) new RadioElement(f.DisplayName)); var sortPicker = new ThemedRootElement("Sort by", new RadioGroup(null, selectedSortIndex)) { sortPickerSection }; // create the "Choose Sort" form var root = new ThemedRootElement("Choose Sort") { new Section() { sortPicker }, new Section() { removeButtonList }, }; // create the DVC and add a "Done" button and handler var dvc = new DialogViewController(root); dvc.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate { // store the current listbox and orderby field, and re-render the list var field = fields[sortPicker.RadioSelected]; Source.OrderBy = field.Name; // store the sort order ListMetadataHelper.StoreListSortOrder( App.ViewModel.PhoneClientFolder, Source.List.ID == Guid.Empty ? (ClientEntity) Source.Folder : (ClientEntity) Source.List, Source.OrderBy); // sync with the service // (do not sync for operations against $ClientSettings) //App.ViewModel.SyncWithService(); // return to parent dvc.NavigationController.PopViewControllerAnimated(true); }); dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground); // add the click handler for the remove button removeButton.Clicked += delegate { // clear the sort Source.OrderBy = null; // store the sort order ListMetadataHelper.StoreListSortOrder( App.ViewModel.PhoneClientFolder, Source.List.ID == Guid.Empty ? (ClientEntity) Source.Folder : (ClientEntity) Source.List, null); // sync with the service // (do not sync for operations against $ClientSettings) //App.ViewModel.SyncWithService(); // return to parent dvc.NavigationController.PopViewControllerAnimated(true); }; // display the form this.NavigationController.PushViewController(dvc, true); }); return sortButton; }