camimamedov
Topic Author
Posts: 6
Joined: 16 Feb 2024, 08:54

Value Converter binding converter failed to convert value 'null'

19 Feb 2024, 13:07

I created a converter that changes width value
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
	int width;
	if (value == null || !int.TryParse(value.ToString(), out width)) width = 0;
	double factor;
	if (parameter == null || !double.TryParse(parameter.ToString(), out factor)) factor = 0;

	return width * factor;
}
But in Unity I get this errors
'Dynamicbox.Converters.GridWidthConverter' binding converter failed to convert value 'null' (type 'Int32')
Binding failed: Path=GridWidth, Source=ViewModel(''), Target=Grid('gridPlayerLevelBar'), TargetProperty=FrameworkElement.Width

How can I fix this problem?
 
User avatar
sfernandez
Site Admin
Posts: 3005
Joined: 22 Dec 2011, 19:20

Re: Value Converter binding converter failed to convert value 'null'

19 Feb 2024, 13:28

Try returning the value as a float, because I guess this converter was applied to the Width property of a UI element, right?
return (float)(width * factor);
There is a known issue regarding the values returned by converters, #1376, so for now the converters need to return the type of the target property.
 
camimamedov
Topic Author
Posts: 6
Joined: 16 Feb 2024, 08:54

Re: Value Converter binding converter failed to convert value 'null'

20 Feb 2024, 07:32

Thank you, this solved the problem

Who is online

Users browsing this forum: nevayeshirazi and 4 guests