[Proposal] Is In Range Converter
See original GitHub issueIsInRangeConverter
- 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 }),
};
}
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Proposal of a DC-DC converter with wide conversion range ...
The proposed converter supports a wide input voltage range that makes it possible to be supplied from 12 V DC to 340 V...
Read more >Propose Data Types Based on Simulation Ranges
Convert to Fixed Point. The app generates an instrumented MEX function for your entry-point MATLAB function. The app displays compiled information—type, ...
Read more >A function to convert any range to a container
We propose a function to copy or materialize any range (containers ... //Supports converting associative container to sequence containers.
Read more >How to Increase Your Proposal Conversion Rate by 25%
We looked at the conversion rates of all proposals that were sent within ... proposal templates on this site from a whole range...
Read more >Part 15 - Contracting by Negotiation
Communications are exchanges, between the Government and offerors, after receipt of proposals, leading to establishment of the competitive range.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@brminnick I think that this proposal an be moved to the
Closed
project column andCompleted
project column to close.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.