Bug 34037 - ConverterParameter not correctly evaluated
Summary: ConverterParameter not correctly evaluated
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Stephane Delcroix
Depends on:
Reported: 2015-09-17 14:36 UTC by adamhewitt
Modified: 2015-10-12 14:27 UTC (History)
6 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description adamhewitt 2015-09-17 14:36:00 UTC
I'm not sure if this applies to bindings in general, but here is my situation:

In a MultiTrigger, I have:

<BindingCondition Value="True" Binding="{Binding Property, Source={x:Reference PageRoot}, Converter={valueConverters:ConverterMarkupExtension}, ConverterParameter={x:Type ns:AnObjectType}}" />

When constructed like that, "parameter" in the Convert call is always null. However, it will work if I move the ConverterParameter like so:

<BindingCondition Value="True" Binding="{Binding Property, ConverterParameter={x:Type ns:AnObjectType}, Source={x:Reference PageRoot}, Converter={valueConverters:ConverterMarkupExtension}}" />

It failed with both the {x:Type} (my use) and a literal 123456.
Comment 1 Stephane Delcroix 2015-09-21 09:39:10 UTC
I'm a bit puzzled by


this refers to a type, when the Converter usually take an instance, like in

    Converter={StaticResource MyConverterMarkup}

Is this a copy-paste issue, or are you really using the Converter that way ?
Comment 2 Stephane Delcroix 2015-09-21 09:54:38 UTC
I tried replicating the difference in behavior using this XAML

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
			<local:Bz34037Converter0 x:Key="MyConverter0" />
			<local:Bz34037Converter1 x:Key="MyConverter1" />
		<Switch x:Name="s0">
				<MultiTrigger TargetType="Switch">
						<BindingCondition Value="True"
										  Binding="{Binding Property, Source={x:Reference PageRoot}, Converter={StaticResource MyConverter0}, ConverterParameter={x:Type x:String}}" />
					<Setter Property="Switch.IsToggled" Value="True" />
		<Switch x:Name="s1">
				<MultiTrigger TargetType="Switch">
						<BindingCondition Value="True" 
										  Binding="{Binding Property, ConverterParameter={x:Type x:String}, Source={x:Reference PageRoot}, Converter={StaticResource MyConverter1}}" />
					<Setter Property="Switch.IsToggled" Value="True" />

In both cases, the converter is invoked with the right ConverterParameter. Could you please provide the simplest possible test case showcasing the bug you describe ?

Thanks a lot

The Xamarin.Forms team
Comment 3 adamhewitt 2015-09-21 11:11:05 UTC
Using your example, I saw the same behavior as you - that is, working well. I then modified it to match my converter usage, and replicated the error.


This leverages a custom markup extension to use a converter where needed without needing to worry about declaring it in resources. For example:

    class Bz34037Converter0 : IValueConverter, IMarkupExtension
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            return null;

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            return null;

        public object ProvideValue(IServiceProvider serviceProvider)
            return new Bz34037Converter0();

The second Switch works with either converter, since it matches my original post.
Comment 4 Stephane Delcroix 2015-09-22 04:46:28 UTC
I've never seen this construct used before, but indeed, it triggers the issue
Comment 5 Rui Marinho 2015-09-30 12:22:10 UTC
Should be fixed in 1.5.1-pre1