In general: the ConvertBack()
method is required to accept the current value stored in the binding target, and convert it back to the type needed for the binding source.
Unfortunately, you have not provided a good Minimal, Complete, and Verifiable example that shows clearly what you are doing. Unless you do, it will be impossible to provide an answer that is guaranteed to address your specific concern. But from the information you've provided, some basic observations and suggestions can be made:
- First, your
Convert()
method appears to have two basic modes: if the source value has Typ
property having the value k1000
, then you return the LowerBorder
property value directly. Otherwise, you format the LowerBorder
property value to a string (apparently a hexadecimal value) and return that.
- Since you are formatting in some cases the
LowerBorder
value as a hexadecimal string, it seems reasonable to assume this property has an integral type, e.g. int
.
- To convert back, you'll need to be able to differentiate these two cases, and reverse the conversion. The most obvious difference in the target value that would result from the conversion you've implemented is the trailing
h
character that would occur in one case, but not the other. So, let's use that.
In that case, you might be able to write your ConvertFrom()
method as something like this:
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
string text = (string)value;
return text[text.Length - 1] == 'h' ?
return FromHexString(text) :
return FromInt32(text);
}
where:
Parameter FromHexString(string text)
{
Parameter parameter = new Parameter();
parameter.Typ = Parameter.ParamaterTyp.k1001;
parameter.LowerBorder = int.Parse(
text.Substring(0, text.Length - 1), NumberStyles.AllowHexSpecifier);
}
Parameter FromInt32(string text)
{
Parameter parameter = new Parameter();
parameter.Typ = Parameter.ParamaterTyp.k1000;
parameter.LowerBorder = int.Parse(text);
}
Note: I have no idea what the Typ
value should be when the value is hex, so I just made up a new value name of k1001
for the purpose of the example. Indeed, if more than one Typ
value could be possible, you're going to have to make a judgment call as to what Typ
value to use, or you'll have to change the source-to-target conversion so that information is preserved (e.g. use a different trailing character depending on the Typ
value).
If the above is not sufficient for you to understand what the ConvertBack()
method is required to do, and to implement that method to suit your needs, please improve your question so that it includes a good code example, and specific details as to what the code should do in each case.