Bug 54564 - Using the new OnPlatform mechanism in XAML returns an OnPlatform object and not the value assigned for each device
Summary: Using the new OnPlatform mechanism in XAML returns an OnPlatform object and n...
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.4
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
Depends on:
Blocks:
 
Reported: 2017-04-06 09:39 UTC by lanarchyste
Modified: 2017-04-18 12:01 UTC (History)
2 users (show)

Tags:
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 ANSWERED

Description lanarchyste 2017-04-06 09:39:11 UTC
I use the new OnPlatform mechanism on a content page.
It is placed in the resources in the page to be accessible by several components.

Example :
<OnPlatform x:Key="DefaultDateTimeButtonColor" x:TypeArguments="x:String">
     <On Platform="iOS" Value="#1AB394" />
     <On Platform="Android" Value="#2196F3" />
</OnPlatform>

I also tried with the following syntax:
<OnPlatform x:Key="DefaultDateTimeButtonColor" x:TypeArguments="x:String">
     <On Platform="iOS">#1AB394</On>
     <On Platform="Android">#2196F3</On>
</OnPlatform>

Example of use in a binding :
{Binding IsRefreshing, Converter={StaticResource BoolToIconColorConverter}, ConverterParameter={StaticResource DefaultDateTimeButtonColor}}

But when I use it as a parameter in a value converter from a binding, the parameter in the converter class is OnPlatform, not the type defined in the XAML (which is in this example of type string)
Comment 2 Stephane Delcroix 2017-04-18 12:01:53 UTC
This is the expected behavior and hasn't change versus the "old" OmPlatform declaration.

You shouldn't worry about it at all as the `OnPlatform<string>` object your converter gets as `converterParameter` can be casted to a `string`, and has to be casted anyway for your converter code to compile.