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

Tags: AC XAML
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:
Status:
RESOLVED FIXED

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

    Converter={valueConverters:ConverterMarkupExtension}

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"
			 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
			 x:Class="Xamarin.Forms.Xaml.UnitTests.Bz34037"
			 xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests"
			 x:Name="PageRoot">
	<ContentPage.Resources>
		<ResourceDictionary>
			<local:Bz34037Converter0 x:Key="MyConverter0" />
			<local:Bz34037Converter1 x:Key="MyConverter1" />
		</ResourceDictionary>
	</ContentPage.Resources>
	<StackLayout>
		<Switch x:Name="s0">
			<Switch.Triggers>
				<MultiTrigger TargetType="Switch">
					<MultiTrigger.Conditions>
						<BindingCondition Value="True"
										  Binding="{Binding Property, Source={x:Reference PageRoot}, Converter={StaticResource MyConverter0}, ConverterParameter={x:Type x:String}}" />
					</MultiTrigger.Conditions>
					<Setter Property="Switch.IsToggled" Value="True" />
				</MultiTrigger>
			</Switch.Triggers>
		</Switch>
		<Switch x:Name="s1">
			<Switch.Triggers>
				<MultiTrigger TargetType="Switch">
					<MultiTrigger.Conditions>
						<BindingCondition Value="True" 
										  Binding="{Binding Property, ConverterParameter={x:Type x:String}, Source={x:Reference PageRoot}, Converter={StaticResource MyConverter1}}" />
					</MultiTrigger.Conditions>
					<Setter Property="Switch.IsToggled" Value="True" />
				</MultiTrigger>
			</Switch.Triggers>
		</Switch>
	</StackLayout>
</ContentPage>

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.

    Converter={local:Bz34037Converter0}

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