user3753452
user3753452

Reputation: 139

Updating the name of the menu item dynamically upon click

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

Answers (1)

Anindya Dutta
Anindya Dutta

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

Related Questions