Correct 'OnPlatform' syntax in XAML?

KevelopKevelop ✭✭NLMember ✭✭

I'm trying to understand why this snippet is throwing a XAML parse error at runtime:

     <Style x:Key="MyButton" TargetType="Button">
                    <Setter Property="BackgroundColor" Value="Transparent"/>
                    <Setter Property="FontSize" Value="36" />
                    <Setter Property="BorderWidth">
                        <Setter.Value>
                            <OnPlatform x:TypeArguments="x:Double">
                                <OnPlatform.iOS Value="2" />
                                <OnPlatform.Android Value="0" />
                            </OnPlatform>
                        </Setter.Value>
                    </Setter>
                </Style>

What's wrong with this syntax, the exception doesn't give me any details.

Best Answer

Answers

  • AlessandroCaliaroAlessandroCaliaro ✭✭✭✭✭ ITMember ✭✭✭✭✭

    is this all your XAML? you have no message from the exception?

  • KevelopKevelop ✭✭ NLMember ✭✭

    The exception is: System.ArgumentNullException: Value cannot be null.
    Parameter name: clrNamespace

    There is lots more styling in the app.Xaml, but this is the only/first one with the Platform differentation.
    If i change the borderwidth setter back to
    <Setter Property="BorderWidth" Value="2" />
    everything is ok...

  • KevelopKevelop ✭✭ NLMember ✭✭

    @NMackay thanks, your solution works!

    However, what i was trying to achieve is not... Android still draws a silly border or something that looks like a shadow around my button... back to the drawing table :neutral:

  • NMackayNMackay mod GBInsider, University mod
  • ArunArun ✭✭ Member ✭✭
    edited June 2018

    Hi @NMackay
    I have followed the style you mentioned to set height using "HeightRequest" and I'm using Xamarin Forms v2.5.1.527436.
    But I'm getting compilation error 5 out of 10 times while trying to build.
    Error : "No property, bindable property, or event found for 'HeightRequest', or mismatching type between value and property."
    To get build succeed I have to keep on clean and build again till its succeeds and its hectic :(
    Any idea to avoid this?
    Thanks

  • NMackayNMackay mod GBInsider, University mod
    edited June 2018

    @Arun said:
    Hi @NMackay
    I have followed the style you mentioned to set height using "HeightRequest" and I'm using Xamarin Forms v2.5.1.527436.
    But I'm getting compilation error 5 out of 10 times while trying to build.
    Error : "No property, bindable property, or event found for 'HeightRequest', or mismatching type between value and property."
    To get build succeed I have to keep on clean and build again till its succeeds and its hectic :(
    Any idea to avoid this?
    Thanks

    That's an issue with the tooling.I get random phantom compilation errors for valid xaml. You could try the last stable build of 2.5.0 and the latest stable VS2017 (15.7.3 at time of writing). The xaml parser can be a bit aggressive and throw up false warnings and of course VS2017 shows errors that don't exist, clean and build usually gets rid of it. You could try clearing your nuget cache (Tools->Options->Nuget Package Manager (Clear All Nuget Caches), clear your object and bins, close VS and restore nugets, might help. I've noticed things get much worse when flipping between a Forms 3.0.0. .NetStandard 2.0 project and a .NetStandard 1.0. 2.5x project.

Sign In or Register to comment.