-
Notifications
You must be signed in to change notification settings - Fork 493
Add New Enum Description Converter #3137
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
Open
BillyMartin1964
wants to merge
26
commits into
CommunityToolkit:main
Choose a base branch
from
BillyMartin1964:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
db71c82
Add EnumDescriptionConverter
BillyMartin1964 64a31a4
Merge branch 'EnumDescriptionConverter'
BillyMartin1964 ee49e0f
Update EnumDescriptionConverter to support DisplayAttribute localization
BillyMartin1964 2b2d254
Merge branch 'EnumDescriptionConverter'
BillyMartin1964 17ecc76
Update Enum converter tests to use BaseOneWayConverterTest
BillyMartin1964 eb5927b
Merge branch 'EnumDescriptionConverter'
BillyMartin1964 745cfc3
Update Enum converter tests to use ICommunityToolkitValueConverter
BillyMartin1964 6384d8a
Merge branch 'EnumDescriptionConverter'
BillyMartin1964 7cf4bf7
Add EnumDescriptionConverter
BillyMartin1964 94edbf7
Add EnumDescriptionConverter
BillyMartin1964 1ff4d6a
Refactor EnumDescriptionConverter UI elements with styling and spacin…
BillyMartin1964 120e642
Merge branch 'RefactorToRemoveReflection'
BillyMartin1964 121742e
Update EnumDescriptionGenerator.cs
TheCodeTraveler d0afca0
Merge branch 'main' into main
TheCodeTraveler f18eff0
Refactor EnumDescriptionConverter UI Elements for Improved Readability
BillyMartin1964 295496b
Refactor EnumDescriptionConverter UI elements for improved readability
BillyMartin1964 150791c
Merge branch 'main' into RefactorToRemoveReflection
BillyMartin1964 28304c1
Refactor EnumDescriptionGeneratorHelper to remove reflection
BillyMartin1964 4f21f71
Merge branch 'RefactorToRemoveReflection'
BillyMartin1964 6e4e5ba
Merge branch 'main' into main
BillyMartin1964 dd4d8f4
Merge branch 'main' into main
TheCodeTraveler 012182e
Update samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/Enu…
TheCodeTraveler 0c6f83f
Update samples/CommunityToolkit.Maui.Sample/MauiProgram.cs
TheCodeTraveler 5413fef
Update samples/CommunityToolkit.Maui.Sample/Pages/Converters/EnumDesc…
TheCodeTraveler 69b243c
Update samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sam…
TheCodeTraveler 3a012cd
Update src/CommunityToolkit.Maui/Converters/EnumDescriptionConverter.cs
TheCodeTraveler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,8 +30,7 @@ | |
| <NoWarn>IL2026</NoWarn> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup Condition="'$(Configuration)' == 'Release' | ||
| AND $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'windows'"> | ||
| <PropertyGroup Condition="'$(Configuration)' == 'Release'
 AND $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'windows'"> | ||
| <!-- Windows error NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. --> | ||
| <PublishAot>false</PublishAot> | ||
| <PublishTrimmed>true</PublishTrimmed> | ||
|
|
@@ -85,6 +84,18 @@ | |
| <ProjectReference Include="..\..\src\CommunityToolkit.Maui.Maps\CommunityToolkit.Maui.Maps.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you revert those changes? |
||
| <Compile Update="Pages\Converters\EnumDescriptionConverterPage.xaml.cs"> | ||
| <DependentUpon>EnumDescriptionConverterPage.xaml</DependentUpon> | ||
| </Compile> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <MauiXaml Update="Pages\Converters\EnumDescriptionConverterPage.xaml"> | ||
| <Generator>MSBuild:Compile</Generator> | ||
| </MauiXaml> | ||
| </ItemGroup> | ||
|
|
||
| <PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))=='windows' and $(Configuration) == 'Release'"> | ||
| <RuntimeIdentifier>win-x64</RuntimeIdentifier> | ||
| </PropertyGroup> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
samples/CommunityToolkit.Maui.Sample/Pages/Converters/EnumDescriptionConverterPage.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <pages:BasePage | ||
| x:Class="CommunityToolkit.Maui.Sample.Pages.Converters.EnumDescriptionConverterPage" | ||
| xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages" | ||
| xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" | ||
| xmlns:vm="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Converters" | ||
| Title="EnumDescriptionConverter" | ||
| x:DataType="vm:EnumDescriptionConverterViewModel" | ||
| x:TypeArguments="vm:EnumDescriptionConverterViewModel"> | ||
|
|
||
| <pages:BasePage.Resources> | ||
| <ResourceDictionary> | ||
| <toolkit:EnumDescriptionConverter x:Key="EnumDescriptionConverter" /> | ||
| </ResourceDictionary> | ||
| </pages:BasePage.Resources> | ||
|
|
||
| <pages:BasePage.Content> | ||
| <VerticalStackLayout Padding="20" Spacing="20"> | ||
| <Label VerticalOptions="Center"> | ||
| <Label.FormattedText> | ||
| <FormattedString> | ||
| <Span Text="The" /> | ||
| <Span FontAttributes="Bold" Text=" EnumDescriptionConverter " /> | ||
| <Span Text="converts Enum values into readable text so they display nicely in the UI." /> | ||
| </FormattedString> | ||
| </Label.FormattedText> | ||
| </Label> | ||
| <Label Text="When an Enum value is passed in, the converter looks for attributes that provide a more user-friendly name. If one is found, it uses that value; otherwise it simply uses the Enum’s name.. " VerticalOptions="Center" /> | ||
TheCodeTraveler marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Label Text="This ensures that Enum values can be displayed clearly while still working correctly even when no attributes are defined. " VerticalOptions="Center" /> | ||
| <Label Text="There is no description needed for one word enum members that are spelled the way you want to display them." /> | ||
|
|
||
|
|
||
| <Border | ||
| Margin="0,20,0,0" | ||
| Padding="15,10" | ||
| Background="LightGray" | ||
| StrokeShape="RoundRectangle 8"> | ||
| <HorizontalStackLayout Spacing="10"> | ||
| <Label | ||
| FontSize="16" | ||
| Text="Without Converter:" | ||
| TextColor="DarkRed" /> | ||
| <Label | ||
| FontAttributes="Bold" | ||
| FontSize="16" | ||
| Text="{Binding SelectedMode}" | ||
| TextColor="DarkRed" /> | ||
| </HorizontalStackLayout> | ||
| </Border> | ||
| <Border | ||
| Padding="15,10" | ||
| Background="LightGray" | ||
| StrokeShape="RoundRectangle 8"> | ||
| <HorizontalStackLayout Spacing="10"> | ||
| <Label | ||
| FontSize="16" | ||
| Text="With Converter:" | ||
| TextColor="DarkRed" /> | ||
| <Label | ||
| FontAttributes="Bold" | ||
| FontSize="16" | ||
| Text="{Binding SelectedMode, Converter={StaticResource EnumDescriptionConverter}}" | ||
| TextColor="DarkRed" /> | ||
| </HorizontalStackLayout> | ||
| </Border> | ||
| </VerticalStackLayout> | ||
| </pages:BasePage.Content> | ||
| </pages:BasePage> | ||
12 changes: 12 additions & 0 deletions
12
samples/CommunityToolkit.Maui.Sample/Pages/Converters/EnumDescriptionConverterPage.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using CommunityToolkit.Maui.Sample.ViewModels.Converters; | ||
|
|
||
| namespace CommunityToolkit.Maui.Sample.Pages.Converters; | ||
|
|
||
| public partial class EnumDescriptionConverterPage : BasePage<EnumDescriptionConverterViewModel> | ||
| { | ||
| public EnumDescriptionConverterPage(EnumDescriptionConverterViewModel enumDescriptionConverterViewModel) | ||
| : base(enumDescriptionConverterViewModel) | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...s/CommunityToolkit.Maui.Sample/ViewModels/Converters/EnumDescriptionConverterViewModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel; | ||
| using System.ComponentModel.DataAnnotations; | ||
| using System.Text; | ||
TheCodeTraveler marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| using CommunityToolkit.Mvvm.ComponentModel; | ||
|
|
||
| namespace CommunityToolkit.Maui.Sample.ViewModels.Converters; | ||
|
|
||
| public partial class EnumDescriptionConverterViewModel : BaseViewModel | ||
| { | ||
| [ObservableProperty] | ||
| public partial ModeName SelectedMode { get; set; } | ||
|
|
||
| public EnumDescriptionConverterViewModel() | ||
| { | ||
| SelectedMode = ModeName.DarkMode; | ||
| } | ||
| } | ||
|
|
||
| public enum ModeName | ||
| { | ||
| // No Description needed for one word enum members that | ||
| // are spelled the way you want to display them | ||
|
|
||
| [Description("Light Mode")] // Can Use Description attribute | ||
| LightMode, | ||
| [Display(Name = "Dark Mode")] // Or Display attribute with Name property | ||
| DarkMode, | ||
| System | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.