I am binding a dependency property to textboxex in WPF. The property is a string that has some values separated by ‘/’ (example: “1/2/3/4” ). I need to bind individual values to separate textboxes which is fine with following implementation of Convert() method:
public object Convert(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture)
{
if (!string.IsNullOrEmpty(value as string))
{
String[] data = (value as string).Split('/');
return data[Int16.Parse(parameter as string)];
}
return String.Empty;
}
And I am using the ConverterParameter in xaml to specify the position of wanted value.
However, the problem is with ConvertBack() method. I do not know, how to get the source value so I could just add or change just one value in the string (on the specified position).
Thanks for any help.
In most cases, you can safely make
ConvertBackjust throwNotImplementedException.Indeed, you just haven’t got enough information to recreate the source value from its part!
If you really need the back conversion (e.g., if you use two-direction binding), I would split the property into 3 strings in the view model (the class used in
DataContext), and bind to them separately.