I have a TextBox in XAML which I'm trying to databind to a nullable int. This is the code for my textbox and linked converter:
<TextBox x:Name="textArea" InputScope="Number" Text="{Binding Area, Mode=TwoWay, Converter={StaticResource NullableValueConverter}}" />
public class NullableValueConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (String.IsNullOrEmpty(value.ToString()))
{
return null;
}
return value;
}
}
When every I enter a number in this textbox the databind doesn't seem to work and the datasource is always left as null. How can I get round this?
I'm using XAML & C# to design a windows store application.
Thanks in advance.