CSS stylesheet in native platform

I used StyleSheet with xamarin.forms and the application works fine.
I put the styles.css file in the shared project.
Now I want to move it in the project of each platform.
How to do that?

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Why do you want to place your styles files on each platform? If you want to implement platform related css styles, you can create two styles.css then use OnPlatform syntax to set different styles for different platforms:

    <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>
    

    These two css files can both be placed in Forms project.

  • MohamedBenSaidMohamedBenSaid USMember ✭✭

    @LandLu
    I have multiple Android projects in my solution. Every project is for a client. The only difference is in the resources (drawables, strings.xml, color.xml, ...) and styles.css.

  • LeonidProtsenkoLeonidProtsenko USMember ✭✭
    edited February 17

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

  • LeonidProtsenkoLeonidProtsenko USMember ✭✭
    edited February 17

    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

Sign In or Register to comment.