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] Is In Range Converter #65

Closed
10 tasks done
TheCodeTraveler opened this issue Sep 25, 2021 · 6 comments · Fixed by #582
Closed
10 tasks done

[Proposal] Is In Range Converter #65

TheCodeTraveler opened this issue Sep 25, 2021 · 6 comments · Fixed by #582
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 proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail

Comments

@TheCodeTraveler
Copy link
Collaborator

TheCodeTraveler commented Sep 25, 2021

IsInRangeConverter

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

Summary

The IsInRangeConverter is a converter that allows users to convert a object value into a boolean value, checking if the value is between MinValue and MaxValue, returning true if the value is within the range and false if the value is out of the range

Detailed Design

IsInRangeConverter.shared.cs

public class IsInRangeConverter : ValueConverterExtension, IValueConverter
{
  public static readonly BindableProperty MinValueProperty = BindableProperty.Create(nameof(MinValue), typeof(object), typeof(IsInRangeConverter));

  public static readonly BindableProperty MaxValueProperty = BindableProperty.Create(nameof(MaxValue), typeof(object), typeof(IsInRangeConverter));

  public object? MinValue
  {
	get => GetValue(MinValueProperty);
	set => SetValue(MinValueProperty, value);
  }

  public object? MaxValue
  {
	get => GetValue(MaxValueProperty);
	set => SetValue(MaxValueProperty, value);
  }

  public object Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture)
  {
	if (value is not IComparable comparable)
		throw new ArgumentException("is expected to implement IComparable interface.", nameof(value));

	if (MinValue is not IComparable)
		throw new ArgumentException("is expected to implement IComparable interface.", nameof(MinValue));

	if (MaxValue is not IComparable)
		throw new ArgumentException("is expected to implement IComparable interface.", nameof(MaxValue));

	return comparable.CompareTo(MinValue) >= 0 && comparable.CompareTo(MaxValue) <= 0;
  }

  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"
             xmlns:myEnum="MyLittleApp.Models"
             x:Class="MyLittleApp.MainPage">

    <ContentPage.Resources>
        <ResourceDictionary>
          <xct:IsInRangeConverter
                          x:Key="IsInRangeConverter"
                          MaxValue= "1"
                          MinValue= "3" />
        </ResourceDictionary>
    </ContentPage.Resources>

    <StackLayout>
        <Label IsVisible="{Binding Number, Converter={StaticResource IssueStateConverter } }" />

    </StackLayout>
</ContentPage>

C# Usage

class MyPage : ContentPage
{
  public MyPage()
  {
    Content = new StackLayout
    {
      Children = 
      {
          new Label().Bind(Label.IsVisibleProperty, nameof(ViewModel.Number), converter: new IsInRangeConverter { MinValue = 1, MaxValue = 3 }),
      };
    }
  }
}
@TheCodeTraveler TheCodeTraveler added new proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail labels Sep 25, 2021
@TheCodeTraveler TheCodeTraveler added this to the v1.0.0 milestone Sep 25, 2021
@TheCodeTraveler TheCodeTraveler removed this from the v1.0.0 milestone Apr 15, 2022
@GeorgeLeithead
Copy link
Contributor

GeorgeLeithead commented Aug 18, 2022

I have a working prototype here: 65-IsInRangeConverter.
I have samples for most of the IComparable derived types and will work on the others for completeness.
NOTE: I have left in GreaterThan and LessThan capabilities as these are easy in the converter (I do know that CompareConverter already does this).
image

@GeorgeLeithead GeorgeLeithead mentioned this issue Sep 2, 2022
10 tasks
@GeorgeLeithead
Copy link
Contributor

Bump

@TheCodeTraveler TheCodeTraveler added the needs discussion Discuss it on the next Monthly standup label Oct 19, 2022
@TheCodeTraveler
Copy link
Collaborator Author

Hey George! I've added the needs discussion Discuss it on the next Monthly standup label, which means we'll discuss this in our next standup.

In other words, I'll bring raise this to the team to see if any of the maintainers have the bandwidth to Champion this proposal.

@JoonghyunCho JoonghyunCho self-assigned this Oct 31, 2022
@ghost ghost added champion A member of the .NET MAUI Toolkit core team has chosen to champion this feature and removed new labels Oct 31, 2022
@JoonghyunCho
Copy link
Member

Hi George! Thanks for your work on this proposal. I will be championing this proposal. I will bring this to a vote to be approved so you can create a pull request. Thanks.

@ghost ghost added approved This Proposal has been approved and is ready to be added to the Toolkit help wanted This proposal has been approved and is ready to be implemented labels Nov 3, 2022
@TheCodeTraveler TheCodeTraveler removed help wanted This proposal has been approved and is ready to be implemented needs discussion Discuss it on the next Monthly standup labels Nov 3, 2022
@TheCodeTraveler TheCodeTraveler linked a pull request Nov 30, 2022 that will close this issue
10 tasks
@ghost ghost reopened this Dec 1, 2022
@ghost
Copy link

ghost commented Dec 1, 2022

Reopening Proposal.

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

@GeorgeLeithead
Copy link
Contributor

@brminnick I think that this proposal an be moved to the Closed project column and Completed project column to close.

@ghost ghost closed this as completed Apr 24, 2023
@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 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.

3 participants