I have a model with the enum property (in this case, associated with the Export Control Rules). When displaying the value to the user, I want to show the corresponding line. Sometimes this happens in ComboBox (where the user can select a value), and sometimes in TextBlock (where it is read-only).
Example: for ExportRegulationType.EAR I want to display "EAR" , and for ExportRegulationType.EAR I want to display "Do Not Export" . Please note that I have no language localization requirements, but I understand the problem ...
Currently in my ViewModel, I have a property that returns a string based on the current value of the enumeration, as well as another property that returns Dictionary<ExportRegulationType, string> . For ComboBoxes, I can bind ItemsSource to a dictionary property, and for TextBlocks I can bind to a string property. It works, but rather clumsy.
Two questions:
1) It seems to me that I should declare the dictionary (with keys and values) as a static resource in XAML (possibly in App.xaml) and use it for the ItemsSource version for ComboBox. However, I cannot understand how to declare and refer to such a thing. How can i do this?
2) Assuming that this was done, I think that I could also set the binding to the text block, so, based on the enum property, it will look for a string in the dictionary.
I saw the following questions related to static or dynamic enumeration value. The first is not adequate, and the second does not respond ...
It should be only XAML, and it will allow me to remove methods from my ViewModel (having only one ExportRegulationType property ExportRegulationType . Is this possible?
Edit: Additional information:
In the application, I will have many different sets of views, models, and ViewModels. However, since export control standards are a general and consistent requirement, I use the composition to keep it DRY. that is, models A and B have an ExportControl model. ViewModels A1, A2, B1 and B2 will have an ExportControlViewModel. Views will have controls associated with the ExportControlViewModel of their ViewModel. Views will have either a ComboBox or TextBlock, but not both (depending on whether the user can change the value).