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

Styles defined in App.xaml Resource Dictionary are not created at runtime

$
0
0

I'm trying to counteract my preference for a code-based UI by using XAML whenever possible. I watched the video "What's New in Xamarin Forms 1.3" (which is excellent) and ran a few examples including "Working With Styles" found here: https://github.com/xamarin/xamarin-forms-samples/tree/master/WorkingWithStyles

I noticed this style defined in App.xaml ...
<Style TargetType="Label">
<Setter Property="TextColor" Value="Green" />
</Style>

... and expected that a label without any style definition would be green. I added a label without a style definition and it was not green.

I tried naming the style in App.xaml "greenLabel"...
<Style x:Key="greenLabel" TargetType="Label">
<Setter Property="TextColor" Value="Green" />
</Style>

... and added a label referencing this style in StyleXaml.xaml...
<Button Style="{StaticResource greenLabel}" Text="App.xml Style" />

The app displayed this error message: "Xamarin.Forms.Xaml.XamlParseException: Position 31:11. StaticResource not found for key greenLabel"

Defining the style in code in App.xaml.cs works as this sample project illustrates with a style named "AppStyle".

It appears that styles defined in the App.xaml Resource Dictionary are not created at runtime.


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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