Bug 54549 - OnPlatform Windows in XAML is missing
Summary: OnPlatform Windows in XAML is missing
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jimmy [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-04-06 06:55 UTC by Novak Savic
Modified: 2017-04-27 21:35 UTC (History)
4 users (show)

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


Attachments
OnPlatform s_valueConverter is null (83.96 KB, image/png)
2017-04-26 14:00 UTC, Taylor Buchanan
Details


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 Novak Savic 2017-04-06 06:55:04 UTC
It seems that options available in XAML and in C# code are not aligned.
In C# we have: Android, iOS, Windows, WinPhone, but in XAML Windows option is missing.
Comment 1 Jimmy [MSFT] 2017-04-06 16:06:44 UTC
Thank you for filing this report! 

Are you talking about the new OnPlatform XAML syntax introduced in Forms 2.3.4[1]? 
I created a new sample project and used the following without any issue:

<Style TargetType="Label">
    <Setter Property="FontSize">
        <Setter.Value>
            <OnPlatform x:TypeArguments="x:Double">
                <On Platform="iOS">21</On>
                <On Platform="Android">42</On>
                <On Platform="Windows">72</On>
            </OnPlatform>
        </Setter.Value>
    </Setter>
</Style>



Are you seeing an error or crash when doing this? Can you attach a project that reproduces the issue? Thanks!

[1] https://github.com/xamarin/Xamarin.Forms/pull/658
Comment 2 Novak Savic 2017-04-06 18:30:16 UTC
Hi Jimmy.

I was trying old syntax, something like:
 <OnPlatform x:TypeArguments="x:Double" iOS="21" Android="42" Windows="72"/>

I get compilation error since Windows is not supported, only WinPhone. I will try new syntax, but somehow I think I also saw some problem there.
Comment 3 Dániel Buga 2017-04-13 07:29:48 UTC
The following snippet fails to assign the data template on XF 2.3.5-beta1 on Windows:

<ListView.ItemTemplate>
    <OnPlatform x:TypeArguments="DataTemplate">
        <On Platform="Android, iOS">
            <DataTemplate>
                <TextCell Text="{Binding Name}" />
            </DataTemplate>
        </On>
        <On Platform="Windows">
            <DataTemplate>
                <ViewCell>
                    <Label Text="{Binding Name}" Margin="5" />
                </ViewCell>
            </DataTemplate>
        </On>
    </OnPlatform>
</ListView.ItemTemplate>
Comment 4 Taylor Buchanan 2017-04-26 13:56:14 UTC
Novak, WinPhone also applies to Windows in the old syntax.

Dániel, this is an issue in 2.3.4.231 as well.

Jimmy, while this is not necessarily related to the original question I didn't want to create a new ticket just yet since Dániel mentioned an actual issue.

Using OnPlatform fails completely on UWP in Release mode. The default value is always returned instead of the specified value because the s_valueConverter field is always null. This is a huge problem.
Comment 5 Taylor Buchanan 2017-04-26 14:00:44 UTC
Created attachment 21807 [details]
OnPlatform s_valueConverter is null

On UWP in Release mode, s_valueConverter is null for OnPlatform. This is a major issue since this causes the default value for the type to be returned instead of the specified value.
Comment 6 Taylor Buchanan 2017-04-26 16:45:04 UTC
Created a separate ticket for my issue here: https://bugzilla.xamarin.com/show_bug.cgi?id=55636
Comment 7 Jimmy [MSFT] 2017-04-27 21:35:18 UTC
@Novak The "Windows" platform is available in the new OnPlatform Xaml syntax. Note however that in 2.3.5 it will be split into separate "UWP and "WinRT" options[1] instead. If you see any issues when using the new syntax, please open a bug report so we can look into them. Thanks!

@Dániel Can you open new report for this? Thanks!

[1] https://github.com/xamarin/Xamarin.Forms/pull/748