Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Apply style using x:static

$
0
0

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?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>