I've bound my TextBox to a string value via
Text="{Binding AgeText, Mode=TwoWay}"
How can I display string.empty or "" for the string "0", and all other strings with their original value?
Thanks for any help!
Cheers
PS: One way would be a custom ViewModel for the string.. but I'd prefer to do it somehow in the XAML directly, if it's possible.
I think the only way beside using the ViewModel is creating a custom ValueConverter.
So basically your choices are:
ViewModel:
private string ageText;
public string AgeText{
get{
if(ageText.equals("0"))
return string.empty;
return ageText;
}
...
}
ValueConverter:
public class AgeTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value.Equals("0"))
return string.Empty;
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
}
}
I found something on http://www.codeproject.com/KB/books/0735616485.aspx
This will do the trick:
Text="{Binding AgeText, StringFormat='\{0:#0;(#0); }'}"
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With