Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7514999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:39:45+00:00 2026-05-30T00:39:45+00:00

I have in XAML 3 menu items defined (using WPF-MDI): <MenuItem Header=_Generic Name=Generic ToolTip=Generic

  • 0

I have in XAML 3 menu items defined (using WPF-MDI):

<MenuItem Header="_Generic" Name="Generic" ToolTip="Generic Visual Studio designer theme" 
          Command="{Binding Path=SelectGenericTheme}"/>
<MenuItem Header="_Luna" Name="Luna" ToolTip="Blue Windows XP theme"
          Command="{Binding Path=SelectLunaTheme}"/>
<MenuItem Header="_Aero" Name="Aero" ToolTip="Windows Vista/7 theme" 
          Command="{Binding Path=SelectAeroTheme}"/>

And the definitions of the commands and current selection in the ViewModel:

    public enum ESelectedTheme
    {
        Generic,
        Luna,
        Aero
    }

    ESelectedTheme _selectedTheme;

    ICommand _selectGenericThemeCommand;
    public ICommand SelectGenericThemeCommand
    {
        get { return _selectGenericThemeCommand ?? (_selectGenericThemeCommand = new RelayCommand(param => SelectGenericTheme(), 
            param => true)); }
    }

    void SelectGenericTheme()
    {
        _selectedTheme = ESelectedTheme.Generic;
    }


    ICommand _selectLunaThemeCommand;
    public ICommand SelectLunaThemeCommand
    {
        get
        {
            return _selectLunaThemeCommand ?? (_selectLunaThemeCommand = new RelayCommand(param => SelectLunaTheme(),
                param => true));
        }
    }

    void SelectLunaTheme()
    {
        _selectedTheme = ESelectedTheme.Luna;
    }


    ICommand _selectAeroThemeCommand;
    public ICommand SelectAeroThemeCommand
    {
        get
        {
            return _selectAeroThemeCommand ?? (_selectAeroThemeCommand = new RelayCommand(param => SelectAeroTheme(),
                param => true));
        }
    }

    void SelectAeroTheme()
    {
        _selectedTheme = ESelectedTheme.Aero;
    }

I have 2 questions (hope that is allowed inside one post):

  1. I want to bind the IsChecked property in XAML to the value that is selected (_selectedTheme). I think I need to write a converter but I don’t know how.
  2. I made 3 copies of ICommands (one for each theme) … what if I would have 20 themes … is there a way to make this code parameterized?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:39:47+00:00Added an answer on May 30, 2026 at 12:39 am

    It will not be necessary to parameterize the command as the binding will do everything but as noted it would be possible using CommandParameter. Here the converter will get the enum parameter.

    An example:

    <MenuItem Header="_Description" IsCheckable="True"
            IsChecked="{Binding Path=DisplayMode_Current,
                                Converter={StaticResource EnumToBooleanConv},
                                ConverterParameter=Description}" />
    <MenuItem Header="_Web-Page" IsCheckable="True"
            IsChecked="{Binding Path=DisplayMode_Current,
                                Converter={StaticResource EnumToBooleanConv},
                                ConverterParameter=WebPage}" />
    

    The converter can look something like this:

    public class EnumToBooleanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // You could also directly pass an enum value using {x:Static},
            // then there is no need to parse
            string parameterString = parameter as string;
            if (parameterString == null)
                return DependencyProperty.UnsetValue;
    
            if (Enum.IsDefined(value.GetType(), value) == false)
                return DependencyProperty.UnsetValue;
    
            object parameterValue = Enum.Parse(value.GetType(), parameterString);
    
            return parameterValue.Equals(value);
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string parameterString = parameter as string;
            if (parameterString == null)
                return DependencyProperty.UnsetValue;
    
            return Enum.Parse(targetType, parameterString);
        }
    }
    

    As the XAML is still verbose (and redundant!) you could take it further by binding the ItemsSource of the parent MenuItem to the enum values and then work with the ItemTemplate and ItemContainerStyle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xaml file with this code: <GridViewColumn x:Name=lvCol3 Header=Quantità Width=120> <GridViewColumn.CellTemplate> <DataTemplate>
I have a context menu that gets menu items through databinding (I'm using the
I have styled my Menu/ContextMenu/MenuItem controls in App.xaml so that those styles apply to
I'm using WPF Menu. I have about 20 different menu buttons and in my
In Window1.xaml I have menu and display area: <Menu x:Name=TheMenu Width=Auto Height=25 DockPanel.Dock=Top/> <ItemsControl
I have a XAML MenuItem DataBound ItemsSource that is working fine however there is
I have some XAML <ItemsControl Name=mItemsControl> <ItemsControl.ItemTemplate> <DataTemplate> <TextBox Text={Binding Mode=OneWay} KeyUp=TextBox_KeyUp/> </DataTemplate> </ItemsControl.ItemTemplate>
I have a WPF Menu and a Tab control. I would like the list
I have the following (simplifed) section in my XAML file: <Menu Width=Auto Height=20 Background=#FFA9D1F4
I have a WPF application that I'm trying to dynamically add items to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.