Apply style using x:static

KeirLavelleKeirLavelle USMember
edited October 2015 in Xamarin.Forms

Is it possible to apply an entire style, defined in code, in xaml using the { x:static Path:To.Style } markup? I've defined the following style in a static class:

public static readonly Style SettingsHeaderBlock = new Style (typeof (StackLayout)) { Setters = { new Setter { Property = StackLayout.HeightRequestProperty, Value = 35 }, new Setter { Property = StackLayout.HorizontalOptionsProperty, Value = LayoutOptions.Start }, new Setter { Property = StackLayout.BackgroundColorProperty, Value = Color.FromHex ("#01409f") }, new Setter { Property = StackLayout.PaddingProperty, Value = new Thickness (20,0,20,0) } } };

the class is called resources, and I have added it to the xaml page using xmlns notation at the top of the page - however when I try and apply the style like so:

<StackLayout Style="{ x:Static Root:Resources.SettingsHeaderBlock }">

I get the following exception thrown:

Xamarin.Forms.Xaml.XamlParseException: Cannot assign property "Content": type mismatch between "System.String" and "Xamarin.Forms.View"

Can someone let me know if this is indeed possible, and if so what I am currently doing wrong?

Tagged:

Best Answer

Answers

  • KeirLavelleKeirLavelle USMember

    I must have had a typo in there somewhere, because I've been through the process again and double checked everything and this is now working

Sign In or Register to comment.