Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How can I set StyleSheet by platform?

LeonidProtsenkoLeonidProtsenko USMember ✭✭
edited February 2019 in Xamarin.Forms

How can I set StyleSheet by platform?

Code:
<StyleSheet Source="{OnPlatform iOS=Styles/AppStylesIos.css, Android=Styles/AppStylesAndroid.css}"/>

Error: Position 6:10. Source property is not a string literal

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Try this:

    <ContentPage.Resources>
        <StyleSheet>
            <StyleSheetExtension.Source>
                <OnPlatform x:TypeArguments="x:Uri">
                    <On Platform="Android">/Assets/Android.css</On>
                    <On Platform="iOS">/Assets/iOS.css</On>
                </OnPlatform>
            </StyleSheetExtension.Source>
        </StyleSheet>
    </ContentPage.Resources>
    
  • LeonidProtsenkoLeonidProtsenko USMember ✭✭

    not works :smile:

    I have error: Position 5:14. StyleSheet require either a Source or a content

    https://forums.xamarin.com/discussion/comment/364907#Comment_364907

  • gabzillagabzilla Member

    having same issue, i cant seem to find an answer everywhere on the net :(
    following @LandLu answer, i also got 'StyleSheet require either a Source or a content'

  • PaulSinnemaPaulSinnema NLMember ✭✭✭

    @LandLu said:
    Try this:

    <ContentPage.Resources>
        <StyleSheet>
            <StyleSheetExtension.Source>
                <OnPlatform x:TypeArguments="x:Uri">
                    <On Platform="Android">/Assets/Android.css</On>
                    <On Platform="iOS">/Assets/iOS.css</On>
                </OnPlatform>
            </StyleSheetExtension.Source>
        </StyleSheet>
    </ContentPage.Resources>
    

    I see this answer often but just as many times not working. What's the solution to this?

Sign In or Register to comment.