How to separate style sheets using Xamarin Forms

Asked

Viewed 27 times

0

Hello, I am coming from WPF where it is possible to create my style files in separate files and from the same use in my UserControl's the same style settings. I did some (many) searches and found some references like this:

https://blog.xamarin.com/easy-app-theming-with-xamarin-forms-styles

But unfortunately I could not understand how to separate my style sheets in a "coherent" way as I am used to doing in WPF or on the web.

Today the common structure I use in my WPF projects is like this:

App
|- App.xaml.cs
|- Assets
   |- Fonts
   |- Styles
      |- Colors.xaml
      |- Fonts.xaml
      ...
   |- Images

And in my root file (App.xaml) I import style dictionaries, like this:

<Application 
    x:Class="Teste.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Teste"
    StartupUri="Views/Dialogs/SplashDialog.xaml">
    <Application.Resources>
      <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
          <ResourceDictionary Source="./Assets/Styles/Colors.xaml"/>
          <ResourceDictionary Source="./Assets/Styles/Fonts.xaml"/>
          <ResourceDictionary Source="./Assets/Styles/Badges.xaml"/>
          <ResourceDictionary Source="./Assets/Styles/Buttons.xaml"/>
          <ResourceDictionary Source="./Assets/Styles/Tabs.xaml"/>
          <ResourceDictionary Source="./Assets/Styles/Aligns.xaml"/>
          <ResourceDictionary Source="./Assets/Styles/Forms.xaml"/>
        </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
    </Application.Resources>
</Application>

How do I apply the same structural "logic" to a Xamarin.Forms application?

  • Checked if the path is right? Just tried <ResourceDictionary Source="Colors.xaml"/>

  • Yes I saw, I have this folder Assets/Styles/ in my root directory of the main Xamarin project

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.