-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Enum values markdown extension #3357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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... 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 🚀 |
Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Type
What kind of change does this PR introduce?
What is the new behavior?
This PR adds a new
EnumValuesExtension
type, a markup extension that can be used to easily assign the list of possible enum values to anItemsSource
property. This is especially useful eg. when using theComboBox
control 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 theText
property 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: