Hello,
Welcome to our Microsoft Q&A platform!
I basically need a project that contains Style(s) (or a ResourceDictionary) that can be accessed by the shared project of Xamarin.Forms
I tried this way to create a share project, then add ResourceDictionary
, but When I use it in xamarin(I added the share reference).
<ResourceDictionary>
<!-- Add more resources here -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/StyleProject;component/Dictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Add more resources here -->
</ResourceDictionary>
But when I build my project, I get Resource "/StyleProject;component/Dictionary1.xaml" not found.
it is not work.
So you can create a CSS file for sharing style. Then you can copy this CSS file to other Projects,
For example, I write a following css style. allow for targeting object types in Xamarin.Forms directly using a ^:
^ContentPage {
background-color: #B9BAA3;
padding: 15;
}
^Label {
text-align: center;
font-style: bold;
font-size: 30;
color: #A22C29;
}
#LoginForm {
background-color: #D6D5C9;
padding: 15;
border-radius: 5;
margin-top: 20
}
^Entry {
font-size: 30;
background-color: white;
margin: 10 0;
color: #0A100D;
}
^Button {
font-size: 16;
color: #A22C29;
margin: 5 0;
}
^Button.primary {
background-color: #902923;
color: #FFFFFF;
font-size: 20;
margin: 15 0;
}
And set the build action is Embedded resource
If I use this style.
<ContentPage.Resources>
<StyleSheet Source="Styles.css" />
</ContentPage.Resources>
For more detials, you can google :Styling Xamarin.Forms Apps with CSS -- Visual Studio Magazine
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.