Skip to content
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

[Proposal] IsStringNullOrEmpty Converters #66

Closed
10 tasks done
brminnick opened this issue Sep 25, 2021 · 5 comments · Fixed by #289
Closed
10 tasks done

[Proposal] IsStringNullOrEmpty Converters #66

brminnick opened this issue Sep 25, 2021 · 5 comments · Fixed by #289
Assignees
Labels
approved This Proposal has been approved and is ready to be added to the Toolkit champion A member of the .NET MAUI Toolkit core team has chosen to champion this feature documentation approved help wanted This proposal has been approved and is ready to be implemented proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail
Milestone

Comments

@brminnick
Copy link
Collaborator

brminnick commented Sep 25, 2021

IsStringNullOrEmptyConverter

  • Proposed
  • Prototype
  • Implementation
    • iOS Support
    • Android Support
    • macOS Support
    • Windows Support
  • Unit Tests
  • Sample
  • Documentation

Summary

The IsStringNullOrEmptyConverter is a converter that allows users to convert an incoming string binding to a bool value. This value represents if the incoming binding value is null or empty using string.IsNullOrEmpty.

The IsStringNotNullOrEmptyConverter is a converter that allows users to convert an incoming string binding to a bool value. This value represents if the incoming binding value is null or empty using string.IsNullOrEmpty.

Detailed Design

IsStringNullOrEmptyConverter.shared.cs

public class IsStringNullOrEmptyConverter : ValueConverterExtension, ICommunityToolkitValueConverter
{
  public object Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture) => value is string stringValue ? string.IsNullOrEmpty(stringValue) : throw new InvalidArgumentException("Binding must be of type string")

  public object? ConvertBack(object? value, Type? targetType, object? parameter, CultureInfo? culture) => throw new NotImplementedException();
}

IsStringNotNullOrEmptyConverter.shared.cs

public class IsStringNullOrEmptyConverter : ValueConverterExtension, ICommunityToolkitValueConverter
{
  public object Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture) => value is string stringValue ? !string.IsNullOrEmpty(stringValue) : throw new InvalidArgumentException("Binding must be of type string")

  public object? ConvertBack(object? value, Type? targetType, object? parameter, CultureInfo? culture) => throw new NotImplementedException();
}

Usage Syntax

XAML Usage

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
             x:Class="MyLittleApp.MainPage">

    <ContentPage.Resources>
        <ResourceDictionary>
            <xct: IsStringNullOrEmptyConverter x:Key="IsStringNullOrEmptyConverter" />
        </ResourceDictionary>
    </ContentPage.Resources>

    <StackLayout>

        <Label IsVisible="{Binding MyStringValue, Converter={StaticResource IsStringNullOrEmptyConverter}}" />

    </StackLayout>
</ContentPage>

C# Usage

class MyPage : ContentPage
{
  public MyPage()
  {
    Content = new StackLayout
    {
      Children = 
      {
          new Label().Bind(Label.IsVisibleProperty, nameof(ViewModel.MyString), converter: new IsStringNullOrEmptyConverter()),
      };
    }
  }
}
@brminnick brminnick added pending documentation This feature requires documentation approved This Proposal has been approved and is ready to be added to the Toolkit proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail champion A member of the .NET MAUI Toolkit core team has chosen to champion this feature labels Sep 25, 2021
@brminnick brminnick added this to the v1.0.0 milestone Sep 25, 2021
@brminnick brminnick self-assigned this Sep 25, 2021
@brminnick brminnick added the help wanted This proposal has been approved and is ready to be implemented label Oct 4, 2021
@juansturla
Copy link
Contributor

Hi again! I added the ViewModel for this sample on #132 PR, so the only thing left is modifying the XAML. I can do that if you like :)

@steven62f
Copy link
Contributor

Hi! I want to help with the sample :)

@juansturla
Copy link
Contributor

Well it looks like you already did that before being assigned hahaha

@brminnick brminnick removed the help wanted This proposal has been approved and is ready to be implemented label Oct 16, 2021
@brminnick
Copy link
Collaborator Author

Thanks @StevenHanquez! It is assigned to you.

@brminnick brminnick changed the title [Proposal] IsNullOrEmpty Converters [Proposal] IsStringNullOrEmpty Converters Feb 10, 2022
@ghost ghost added the help wanted This proposal has been approved and is ready to be implemented label Feb 10, 2022
@brminnick brminnick removed help wanted This proposal has been approved and is ready to be implemented approved This Proposal has been approved and is ready to be added to the Toolkit pending documentation This feature requires documentation labels Feb 10, 2022
@brminnick brminnick linked a pull request Feb 10, 2022 that will close this issue
6 tasks
@ghost ghost added the approved This Proposal has been approved and is ready to be added to the Toolkit label Feb 10, 2022
@ghost ghost added the help wanted This proposal has been approved and is ready to be implemented label Feb 10, 2022
@ghost ghost reopened this Feb 11, 2022
@ghost
Copy link

ghost commented Feb 11, 2022

Reopening Proposal.

Only Proposals moved to the Closed Project Column and Completed Project Column can be closed.

@bijington bijington self-assigned this Mar 30, 2022
@ghost ghost closed this as completed Mar 30, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 24, 2024
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved This Proposal has been approved and is ready to be added to the Toolkit champion A member of the .NET MAUI Toolkit core team has chosen to champion this feature documentation approved help wanted This proposal has been approved and is ready to be implemented proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants