Is there a way to transfer null? If I try so, it takes it as 0.
That's because your converter returns 0
when the input is null
. Have a look at your ConvertBack
method (comments added by me):
Int16 result = 0; // result is initialized to 0
// Since `value` is `null`, the if branch is not taken
if (value != null && value.GetType() == typeof(Int32))
{
result = System.Convert.ToInt16(value);
}
return result; // 0 is returned.
The solution is simple: Just keep the return value "nullable":
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (Int16?)value;
}