Reputation: 139
I would like to have the menu item name as "Show" initially and toggle the name of the menuitem to "Hide" when click, and toggle back to "Show" again when click again. It is not working. Please advice. thanks
private void StatisticsFunctionsShowOrHideMenu_OnClick(object sender, RoutedEventArgs e)
{
MenuItem m = sender as MenuItem;
if (m != null)
{
m.Name = m.Name == "Show" ? "Hide" : "Show";
}
}
Upvotes: 0
Views: 527
Reputation: 1982
Replace 'Name' with 'Text'.
private void StatisticsFunctionsShowOrHideMenu_OnClick(object sender, RoutedEventArgs e) {
MenuItem m = sender as MenuItem;
if (m != null) {
m.Text = m.Text == "Show" ? "Hide" : "Show";
}
}
Upvotes: 1