Two and One Way Converter Examples Don't Work

Open Beginner friendly
#651 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
91/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
documentation

Research direction

Open docs/maui/converters/index.md and find the two-way and one-way converter examples referenced by the issue. Correct the documented ConvertFrom and ConvertBackTo return types to match BaseConverter<bool, Color>, then review the rendered examples to confirm both compile conceptually and show the intended signatures.

Written by the indexing model from the issue text.

Description

dotnet-communitytoolkit/svc dotnet-maui-community-toolkit/subsvc Pri2
Type of issue

Code doesn't work

Description

The given examples for creating a two way converter and one way converter have the wrong return types.
The code as written for the two way coverter is:

public class BoolToColorConverter : BaseConverter<bool, Color>
{
    public override Color DefaultConvertReturnValue { get; set; } = Colors.Orange;

    public override bool DefaultConvertBackReturnValue { get; set; } = false;

    public override string ConvertFrom(bool value, CultureInfo? culture)
    {
        return value ? Colors.Green : Colors.Red;
    }

    public override int ConvertBackTo(Color value, CultureInfo? culture)
    {
        return value == Colors.Green;
    }
}

it should be

public class BoolToColorConverter : BaseConverter<bool, Color>
{
    public override Color DefaultConvertReturnValue { get; set; } = Colors.Orange;

    public override bool DefaultConvertBackReturnValue { get; set; } = false;

    public override Color ConvertFrom(bool value, CultureInfo? culture)
    {
        return value ? Colors.Green : Colors.Red;
    }

    public override bool ConvertBackTo(Color value, CultureInfo? culture)
    {
        return value == Colors.Green;
    }
}

The one way converter has the same issue with the overide for ConvertFrom()

Page URL

https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/converters/

Content source URL

https://github.com/MicrosoftDocs/CommunityToolkit/blob/main/docs/maui/converters/index.md

Document Version Independent Id

c058518f-3a9b-7df9-6c1a-ec4bf98eefc6

Platform Id

9ba182ca-81a5-7dfc-3f78-99720fceb9da

Article author

@bijington

Metadata
  • ID: c058518f-3a9b-7df9-6c1a-ec4bf98eefc6
  • PlatformId: 9ba182ca-81a5-7dfc-3f78-99720fceb9da
  • Service: dotnet-communitytoolkit
  • Sub-service: dotnet-maui-community-toolkit
Dominant language
No language data
Stars
168
Forks
134
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MicrosoftDocs/CommunityToolkit

All issues in MicrosoftDocs/CommunityToolkit

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.