string has value converter

This commit is contained in:
Kyle Spearrin 2019-04-29 09:31:34 -04:00
parent 8fa2ef863f
commit 65fe0e8f62

View file

@ -0,0 +1,24 @@
using System;
using Xamarin.Forms;
namespace Bit.App.Utilities
{
public class StringHasValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if(targetType == typeof(bool) && value.GetType() == typeof(string))
{
return !string.IsNullOrWhiteSpace((string)value);
}
throw new InvalidOperationException("The value must be a string with a boolean target.");
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
}