public MenuItemModel(MenuItemModel original) { // Loop on each properties and set it's value using the original one foreach (PropertyInfo property in GetType().GetProperties()) { /// Set to each property its name as value property.SetValue(this, property.GetValue(original)); } }
/// <summary> /// The only way to add correctly items in the menu /// </summary> /// <param name="item">MenuItem to add</param> /// <param name="index">Index to add this item. (-1 by defualt => to the end of the menu) </param> public void AddItem(MenuItemModel item, int index = -1) { if ((index > Items.Count) || (index < -1)) { return; } MenuItemModel originalItem = new MenuItemModel(item); // Set default values if necessary if (originalItem.ImageSize == 0) { originalItem.ImageSize = defaultMenuItemImageSize; } if (originalItem.HeightRequest == 0) { originalItem.HeightRequest = defaultMenuItemHeightRequest; } if (originalItem.WidthRequest == 0) { originalItem.WidthRequest = defaultMenuItemWidthRequest; } // Create displayItem using originalItem MenuItemModel displayItem = new MenuItemModel(originalItem); displayItem.Command = new RelayCommand <object>(new Action <object>(ItemCommand)); // Change Text of display item if necessary if (originalItem.IsSelected) { if (!TextVisibleForSelectedItem) { displayItem.Label = ""; } } else if (!TextVisible) { displayItem.Label = ""; } if (index == -1) { itemsOriginal.Add(originalItem); Items.Add(displayItem); } else { itemsOriginal.Insert(index, originalItem); Items.Insert(index, displayItem); } }