private void IsCheckedChanged(DependencyObject o, DependencyProperty p) { RadioMenuFlyoutItem radioItem = o as RadioMenuFlyoutItem; TextBlock stateText; if (itemStates.TryGetValue(radioItem.Text, out stateText)) { UpdateTextState(radioItem, stateText); } }
private void UpdateMenu <T> (NavigationViewItem navItem, Symbol symbol, NotifyCollectionChangedEventArgs e, SingleSelectionManager <T> manager, T emptyElement = null) where T : NamedElement { var menu = (MenuFlyout)navItem.ContextFlyout; int sepIndex = menu.Items.IndexOf(menu.Items.OfType <MenuFlyoutSeparator> ().First()); int i; for (i = 0; i < sepIndex; i++) { menu.Items.RemoveAt(0); } if (manager.Elements.Count == 0) { if (emptyElement != null) { menu.Items.Insert(0, new MenuFlyoutItem { Text = emptyElement.Name, IsEnabled = false }); } return; } i = 0; foreach (T element in manager.Elements) { var radio = new Microsoft.UI.Xaml.Controls.RadioMenuFlyoutItem { DataContext = new SingleSelectionItemViewModel <T> (manager, element), Icon = new SymbolIcon(symbol) }; radio.SetBinding(MenuFlyoutItem.TextProperty, new Binding { Path = new PropertyPath("Name"), Mode = BindingMode.OneTime }); radio.SetBinding(Microsoft.UI.Xaml.Controls.RadioMenuFlyoutItem.IsCheckedProperty, new Binding { Path = new PropertyPath(nameof(SingleSelectionItemViewModel <NamedElement> .IsSelected)), Mode = BindingMode.TwoWay }); menu.Items.Insert(i++, radio); } }
public RadioMenuFlyoutItemPage() { this.InitializeComponent(); itemStates = new Dictionary <string, TextBlock>(); if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.MenuFlyoutItem", "Icon")) { IconMenuFlyoutItem.Icon = new SymbolIcon(Symbol.Calendar); IconRadioMenuFlyoutItem.Icon = new SymbolIcon(Symbol.Calculator); } if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.Grid", "ColumnSpacing")) { InfoGrid.ColumnSpacing = 12; ItemNames.Spacing = 4; ItemStates.Spacing = 4; } // register all RadioMenuFlyoutItems foreach (MenuFlyoutItemBase item in ButtonMenuFlyout.Items) { 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); } } }
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); } }
private void UpdateTextState(RadioMenuFlyoutItem item, TextBlock textBlock) { textBlock.Text = item.IsChecked ? "Checked" : "Unchecked"; }