private void FlyoutBase_OnOpening(object sender, object e) { var menuflyuout = sender as MenuFlyout; var addon = menuflyuout.Items.First().Tag as Addon; MenuFlyoutItemBase temp = menuflyuout.Items.FirstOrDefault(item => item.Name.Equals("VersionsMenuFlyout")); if (temp != null) { menuflyuout.Items.Remove(temp); var submenu = new MenuFlyoutSubItem() { Name = "VersionsMenuFlyout", Text = "Versions" }; foreach (var download in addon.Downloads) { var menuItem = new MenuFlyoutItem() { Text = download.ToString() }; menuItem.Click += async(a, b) => { if (addon.IsIgnored) { var updateAddonDialog = new ContentDialog() { Title = "Can't update ignored addon", PrimaryButtonText = "Ok" }; var response = await updateAddonDialog.ShowAsync(); } else { var updateAddonDialog = new ContentDialog() { Title = "Update Addon?", Content = "Update to " + download.ReleaseType + " " + download.Version + "?", PrimaryButtonText = "Ok", CloseButtonText = "Cancel" }; var response = await updateAddonDialog.ShowAsync(); if (response == ContentDialogResult.Primary) { await Tasks.UpdateAddon(addon, download); } } }; submenu.Items.Add(menuItem); } menuflyuout.Items.Insert(menuflyuout.Items.Count - 1, submenu); } }
private static void RecurciveSettingDataContext(MenuFlyoutItemBase item, object dataContextToTag) { item.Tag = dataContextToTag; if (item is MenuFlyoutSubItem subItem) { foreach (var child in subItem.Items) { RecurciveSettingDataContext(child, dataContextToTag); } } }
private static void RecurciveSettingDataContext(MenuFlyoutItemBase item, object dataContext) { item.DataContext = dataContext; if (item is MenuFlyoutSubItem) { var subItem = item as MenuFlyoutSubItem; foreach (var child in subItem.Items) { RecurciveSettingDataContext(child, dataContext); } } }
static void SetCommand(MenuFlyoutItemBase b, ICommand c) { if (b is MenuFlyoutSubItem i) { foreach (var child in i.Items) { SetCommand(child, c); } } else if (b is MenuFlyoutItem m) { m.Command = c; } }
private static IEnumerable <DependencyObject> ResolveMenuFlyoutItems(MenuFlyoutItemBase item) { yield return(item); var subItem = item as MenuFlyoutSubItem; if (subItem != null && subItem.Items != null) { foreach (var subSubItem in subItem.Items) { yield return(subSubItem); } } }
static void SetCommand(MenuFlyoutItemBase b, ICommand c) { b.FontSize = 14; if (b is MenuFlyoutSubItem i) { i.Height = 40; foreach (var child in i.Items) { SetCommand(child, c); } } else if (b is MenuFlyoutItem m) { m.Command = c; m.Height = 40; } }
private void RegisterItem(MenuFlyoutItemBase item) { if (item is RadioMenuFlyoutItem) { RadioMenuFlyoutItem radioItem = item as RadioMenuFlyoutItem; radioItem.RegisterPropertyChangedCallback(RadioMenuFlyoutItem.IsCheckedProperty, new DependencyPropertyChangedCallback(IsCheckedChanged)); TextBlock nameText = new TextBlock(); nameText.Text = radioItem.Text; ItemNames.Children.Add(nameText); TextBlock stateText = new TextBlock(); AutomationProperties.SetName(stateText, radioItem.Text + "State"); UpdateTextState(radioItem, stateText); ItemStates.Children.Add(stateText); itemStates.Add(radioItem.Text, stateText); } }
static void SetCommand( MenuFlyoutItemBase b, ICommand c, double fontSize, double height) { b.FontSize = fontSize; if (b is not MenuFlyoutSeparator && height > 0) { b.Height = 40; } if (b is MenuFlyoutSubItem i) { foreach (var child in i.Items) { SetCommand(child, c, fontSize, height); } } else if (b is MenuFlyoutItem m) { m.Command = c; } }
private List <MenuFlyoutItemBase> GenerateMenu(string folderPath, List <MenuInfo> menuInfos) { return(menuInfos.Select(it => { if (string.IsNullOrEmpty(it.Title)) { return new MenuFlyoutSeparator() as MenuFlyoutItemBase; } var title = it.Title.Replace("&", ""); var quickIndex = it.Title.IndexOf('&'); KeyboardAccelerator keyboardAccelerator = null; if (quickIndex != -1) { if (Enum.TryParse <VirtualKey>(it.Title[quickIndex + 1].ToString(), out var quickKey)) { keyboardAccelerator = new KeyboardAccelerator { Key = quickKey }; if (quickIndex > 0 && it.Title[quickIndex - 1] == '(') { var endIndex = it.Title.Substring(quickIndex).IndexOf(')'); if (endIndex != -1) { title = title.Remove(quickIndex - 1, endIndex + 1); } } } } MenuFlyoutItemBase result = null; if (it.SubMenu.Any()) { var subItem = new MenuFlyoutSubItem { Text = title }; GenerateMenu(folderPath, it.SubMenu).ForEach(m => subItem.Items.Add(m)); result = subItem; } else { var item = new MenuFlyoutItem { Text = title, Command = MenuCommand, CommandParameter = new ContextMenuAction { Type = ContextMenuAction.ActionType.InvokeCommand, MenuId = Convert.ToInt32(it.Id), Path = folderPath, } }; result = item; } if (keyboardAccelerator != null) { result.KeyboardAccelerators.Add(keyboardAccelerator); } return result; }).ToList()); }