I have a value converter which I mainly use for data binding of the width property for various controls. But If I use the same converter to bind of Height then I get a variety of error. And I have another problem is, I get null reference error.
Here is the C# code of the Converter which I use for data binding of Width :
public class WpConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Int32.Parse(value.ToString()) - 200;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
This same converter is not working for Height, I don't understand why ? because the main goal is to get a numerical value from the converter. But still my WPF application is crashed whenever I use for data binding of Height of any elements. And another null reference error I get on this line (value.ToString())
.
This converter simply return one time value that means we only get one value at a time. But I want to use the converter multiple times that's why I use a Converter Parameter. Here is the C# code of that same converter but slightly modified to use for Converter Parameter.
public class RectConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double disp;
if (parameter == null || !double.TryParse(parameter.ToString(), out disp)) disp = 142;
return double.Parse(value.ToString()) - disp;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}