Enum values markdown extension#3357
Conversation
|
Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
|
@Sergio0694 Toolkit-CI is failing here. |
|
@Kyaa-dost *sigh*... .NET Native strikes again 🤣 Those are passing locally, I'll try adding the type to the |
|
Well that didn't work. Uhm... 🤔 |
michael-hawker
left a comment
There was a problem hiding this comment.
We need to add the types in the UnitTestApp.xaml file to not get optimized out:
<extensions:EnumValuesExtension x:Key="DummyExtension"/>
<unitTestExtensions:Animal x:Key="Animal">Cat</unitTestExtensions:Animal>We should also have a sample page to show advanced scenarios like DataTemplates (simple and with extra data) and also things like doing conversions on names/etc...?
|
This PR has been marked as "needs attention 👋" and awaiting a response from the team. |
|
Added those tweaks in 4b7eb2a, thanks! 😄 Will work on a sample page then 🚀 |

PR Type
What kind of change does this PR introduce?
What is the new behavior?
This PR adds a new
EnumValuesExtensiontype, a markup extension that can be used to easily assign the list of possible enum values to anItemsSourceproperty. This is especially useful eg. when using theComboBoxcontrol to display a list of available settings. Consider the following example for a settings page in an app:The result is an easy to use collection of values that can be displayed in a variety of ways by tweaking the data template in use. It's also possible to easily localize enum values by using a convention-based pattern for the resource strings. For instance, in my apps I localize enum values using the
[ENUM_TYPE]/[ENUM_VALUE]format. In this case, I simply bind theTextproperty of my template to a convert that grabs the right localization string with that value. (on this note, @michael-hawker let me know if you'd also like me to open a PR to add that converter to the toolkit). Here's a GIF as a reference for the result of this extension:You can see I'm showing a variety of different visual styles for the various selectors, just by changing the data template. All of them are using this extension to load the enum values to display, instead of having a redundant collection property in the viewmodel.
PR Checklist
Please check if your PR fulfills the following requirements: