x: String in XAML Resource Dictionary generates a run-time error

SHRSHR PTMember
edited November 2017 in Xamarin.Forms

Hi,
The use of a x:String type in a ResourceDictionary causes a runtime error System.ArgumentNullException, in the ....xaml.g.cs file:
This happens since Xamarin. Forms version 2.4.0.282!! Yes I tried them all, since the last one performing well (2.4.0.280).

The used example code is:

        <?xml version="1.0" encoding="utf-8"?>
        <ContentPage xmlns=... the usual link ...
            xmlns:x=... the usual link ...
            xmlns:local="clr-namespace:Teste2" x:Class="Teste2.Teste2Page">

          <ContentPage.Resources>
            <ResourceDictionary>
              <x:String x:Key="fontSize">Large</x:String>
            </ResourceDictionary>
          </ContentPage.Resources>

          <StackLayout>
            <Button Text=" Button Example "
                    FontSize="{StaticResource fontSize}" />
          </StackLayout>
        </ContentPage>

Tx in Advance,

Posts

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    I think the site parser mangled your markup.
    Here's an article on how to post to avoid that.
    Please re-post your markup so we can see what you're doing, accurrately.

  • SHRSHR PTMember
    edited November 2017

    Tx. @ClintStLaurent
    Correted in initial post!

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    edited November 2017

    FontSize is a Double. Try it with a number like 40

                <OnPlatform x:Key="FontSizeMedium"
                            x:TypeArguments="x:Double"
                            Android="25.0"
                            WinPhone="25.0"
                            iOS="25.0" />
    
  • SHRSHR PTMember
    edited November 2017

    There is no problem with a Double I know, but that's not the problem I reported!

    The use of x:String for the NamedSize enumeration members in a ResourceDictionary is documented by Xamarin here:

    developer.xamarin.com/guides/xamarin-forms/xaml/xaml-basics/xaml_markup_extensions

    And the example there shows it is possible to use it the way I mentioned.

    PS - Besides The Types Android, WinPhone and iOS are marked System.Obsolet.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    There is no problem with a Double I know

    Terrific, that confirms all the basic binding and references etc. are valid.

    Really quick and dirty experiment on my current app.
    I stuck this in the App.xaml with my other statics

    I stuck this on a page with text saying "Test"

    Ran it on a Samsung tablet- I don't get an exception like you - but the page doesn't display either. So the exception is being swallowed and I don't have it ticked on in the Exception Settings.

    So... At least someone else can reproduce that what you're seeing is a bug. Seems like something you should file a bugzilla on since it is supposed to work that way per documentation.

    I've never bothered trying to use the names sizes - sorry - so I don't have a working sample of how to do that. Personally I always set my sizes as double static references... then use those definitions in my XAML styles. The same plan as spelled out on article 203 of that same site I linked earlier.

Sign In or Register to comment.