Bug 60757 - XAML OnPlatform not work in .Net Standard 2 project
Summary: XAML OnPlatform not work in .Net Standard 2 project
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.5.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-11-19 10:28 UTC by Khuong Nguyen
Modified: 2017-12-07 14:03 UTC (History)
3 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 FIXED

Description Khuong Nguyen 2017-11-19 10:28:08 UTC
The simple code like bellow 'cause build (with XamlCompilation) and runtime error: Xamarin.Forms.Xaml.XamlParseException: Position 7:10. Cannot assign property "Margin": Property does not exists, or is not assignable, or mismatching type between value and property

    <ContentPage.Margin>
        <OnPlatform x:TypeArguments="x:Double">
            <On Platform="Android"
                Value="0"></On>
            <On Platform="iOS"
                Value="0,10,0,0"></On>
        </OnPlatform>
    </ContentPage.Margin>
Comment 1 Paul DiPietro [MSFT] 2017-11-19 14:57:37 UTC

*** This bug has been marked as a duplicate of bug 58922 ***
Comment 2 Khuong Nguyen 2017-11-19 15:24:15 UTC
I think it not like with the #58922 
Here the full sample

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Locator"             
             x:Class="Locator.MainPage">
    <ContentPage.Margin>
        <OnPlatform x:TypeArguments="Thickness">
            <On Platform="Android"
                Value="0"></On>
            <On Platform="iOS"
                Value="0,10,0,0"></On>
        </OnPlatform>
    </ContentPage.Margin>
	<Label Text="Welcome to Xamarin.Forms!" 
           VerticalOptions="Center" 
           HorizontalOptions="Center" />
</ContentPage>

this code work if using PCL or Shared Project but not work on .NETStandard
Comment 3 Jean-Daniel Gasser 2017-12-07 14:03:13 UTC
Hello,
Exact same problem here. 

This code works on PCL:
<Label.WidthRequest>
  <OnPlatform x:TypeArguments="x:Double">
    <On Platform="iOS" Value="140" />
    <On Platform="Android" Value="140" />
    <On Platform="WinPhone, Windows" Value="180" />
  </OnPlatform>
</Label.WidthRequest>

But when I compile the same in a .NET Standard project, then following compilation error appears:
No property, bindable property, or event found for 'WidthRequest', or mismatching type between value and property.