[Proposal] IsStringNullOrEmpty Converters
See original GitHub issueIsStringNullOrEmptyConverter
- 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()),
};
}
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
is-string-null-or-empty-converter.md
The IsStringNullOrEmptyConverter is a one way converter that returns a bool indicating whether the binding value is null or string.Empty.
Read more >Why do I get null instead of empty string when receiving ...
You can use the DisplayFormat attribute on the property of your model class: [DisplayFormat(ConvertEmptyStringToNull = false)].
Read more >IsStringNullOrWhiteSpaceConve...
The IsStringNullOrWhiteSpaceConverter is a one way converter that returns a bool indicating whether the binding value is null or string.
Read more >Bluetooth RFBUS from TOSHIBA_2.1.1127.0_Soft32.exe
Submit malware for free analysis with Falcon Sandbox and Hybrid Analysis technology. Hybrid Analysis develops and licenses analysis tools to fight malware.
Read more >Automated Malware Analysis Report for http://jino.ru
System is w10x64 ... @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)....
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
Well it looks like you already did that before being assigned hahaha
Reopening Proposal.
Only Proposals moved to the
Closed
Project Column andCompleted
Project Column can be closed.