private void AddTrack(TracksMenu tracksMenu, int?trackId, string trackName, bool subTitle = false) { if (tracksMenu == null) { return; } var menuItem = new ToggleMenuFlyoutItem() { Text = trackName, Tag = trackId }; menuItem.Click += TrackMenuItem_Click; var menuItems = tracksMenu.MenuFlyout.Items; menuItems.Add(menuItem); if (menuItems.Count == 2) { var firstMenuItem = (menuItems.FirstOrDefault() as ToggleMenuFlyoutItem); if (subTitle || firstMenuItem?.Tag != null) { firstMenuItem.IsChecked = true; } else { menuItem.IsChecked = true; } VisualStateManager.GoToState(this, tracksMenu.AvailableStateName, true); } }
private void AddTracksMenu(string trackMenuName, TrackType trackType, string availableStateName, string unavailableStateName, bool addNoneItem = false) { if (GetTemplateChild(trackMenuName) is MenuFlyout menu) { var tracksMenu = new TracksMenu() { MenuFlyout = menu, AvailableStateName = availableStateName, UnavailableStateName = unavailableStateName, HasNoneItem = addNoneItem }; TracksMenus.Add(trackType, tracksMenu); if (addNoneItem) { AddNoneItem(tracksMenu); } } }
private void CheckMenuItem(TracksMenu tracksMenu, object menuItem) { ToggleMenuFlyoutItem toggleMenuFlyoutItem; bool isChecked; foreach (var item in tracksMenu.MenuFlyout.Items) { toggleMenuFlyoutItem = item as ToggleMenuFlyoutItem; if (toggleMenuFlyoutItem != null) { isChecked = (item == menuItem); if (toggleMenuFlyoutItem.IsChecked != isChecked) { toggleMenuFlyoutItem.IsChecked = isChecked; } } } }
private void AddNoneItem(TracksMenu tracksMenu) { AddTrack(tracksMenu, null, ResourceLoader?.GetString("None")); }