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 6375703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:39:00+00:00 2026-05-25T01:39:00+00:00

I have a model with an enum property (in this case, related to Export

  • 0

I have a model with an enum property (in this case, related to Export Control Regulations). When displaying the value to the user, I want to show a corresponding string. Sometimes this is in ComboBox (where the user can select a value), and sometimes it is in a TextBlock (where it is read-only).

Example: for ExportRegulationType.EAR, I want to display "EAR", while for ExportRegulationType.DoNotExport, I want to display "Do Not Export". Note that I don’t have any language localization needs, but I recognize the issue…

Currently, in my ViewModel, I have a property that returns a string based on the current enum value, and also another property that returns a Dictionary<ExportRegulationType, string>. For the ComboBoxes, I can bind ItemsSource to the dictionary property, and for the TextBlocks, I can bind to the string property. This works, but is kind of clumsy.

Two questions:

1) It seems to me that I should be able to declare the dictionary (with keys and values) as a static resource in XAML (probably in App.xaml), and use that for the ItemsSource for the ComboBox version. However, I can’t figure out how to declare and reference such a thing. How can I do that?

2) Assuming the above is in place, I would think I could also set up a binding with the textblock, so based on the enum property, it will look up the string in the dictionary.

I have seen the following questions relating to a static or dynamic enum value. The first isn’t adequate, and the second isn’t answered…

These should be a XAML-only, and will enable me to remove the methods from my ViewModel (having only the one exposed ExportRegulationType enumerated property. Are these possible?

Edit: Additional information:

In the application, I will have many different sets of views, models, and ViewModels. However, as export control regulations are a common and consistent requirement, I am using composition to keep it DRY. i.e., Models A and B both have an ExportControl model. ViewModels A1, A2, B1 and B2 will have an ExportControlViewModel. The views will have controls bound to the ExportControlViewModel of their ViewModel. The views will have either a ComboBox or a TextBlock, but not both (Depending on if the user can change the value).

  • 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-25T01:39:00+00:00Added an answer on May 25, 2026 at 1:39 am

    I don’t know if this will work for your case, but here is a possible solution. In your view model, expose a ExportRegulationType property and then create a value converter to display your desired string.

    First create your value converter:

    class ExportRegulationTypeToStringConverter: IValueConverter
    {
        #region IValueConverter Members
    
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ExportRegulationType regType = (ExportRegulationType)value;
    
            switch(regType)
            {
                case ExportRegulationType.EAR:
                    return "EAR";
                case ExportRegulationType.DoNotExport:
                    return "Do Not Export";
    
                //handle other cases
            }
        }
    
        public object ConvertBack(object value, Type targetType, object parameter,    System.Globalization.CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    
        #endregion
    }
    

    Then add a reference to your converter in your xaml. local is the namespace in which your class is located.

    <local:ExportRegulationTypeToStringConverter x:Key="exportRegConverter" />
    

    Finally, set the value of your text box to use the converter. pathToEnum is the property exposed on your ViewModel of type ExportRegulationType.

    <TextBlock Text="{Binding pathToEnum, Converter={StaticResource exportRegConverter}}" />
    

    Use ObjectDataProvider to fill the ComboBox with the values of the enum.

    <Window.Resources>
     <ObjectDataProvider x:Key="dataFromEnum"
       MethodName="GetValues" ObjectType="{x:Type System:Enum}">
          <ObjectDataProvider.MethodParameters>
               <x:Type TypeName="local:ExportRegulationType"/>
          </ObjectDataProvider.MethodParameters>
     </ObjectDataProvider>
    </Window.Resources>
    

    Now we create the ComboBox and use a container style with our value converter to display the desired strings for our enum.

    <ComboBox ItemsSource="{Binding Source={StaticResource dataFromEnum}}">
        <ComboBox.ItemContainerStyle>
            <Style TargetType="ComboBoxItem">
                <Setter Property="Content" Value="{Binding Converter={StaticResource exportRegConverter}}" />
            </Style>
        </ComboBox.ItemContainerStyle>
    </ComboBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an enum. Based upon the value brought by model, I have to
I have an enum for one of the properties of my view-model. I want
I have an enum type on my Java model which I'd like to map
If I have Model.objects.all() I want to get only one object for any content_object=foo,
I have model that is a queue of Strings associated with enum types. I'm
I currently have a model Attend that will have a status column, and this
I have the following view model to query my table: QuestionViewModel.cs public enum TypeQuestion
I have a simple .Net enum. I also have a view model object which
I have a model as follows: namespace MvcApplication1.Models { public enum Sex { Male,
I have defined the following select list: <%= this.Select(Scope) .Options(Scopes.AllValues) // static property to

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.