Issue
In this Xaml code that I insert into another page on my app I have this code:
<?xml version="1.0" encoding="UTF-8"?>
<Grid xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:template="clr-namespace:Japanese.Templates"
x:Class="Japanese.Views.Phrases.Xaml.PhraseQuizInfo"
VerticalOptions="FillAndExpand" Padding="20,0,20,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="33*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="{Binding Deck}" Style="{StaticResource StatusLabel}" />
<Label Grid.Column="1" Text="{Binding Cards}" Style="{StaticResource StatusLabel}" />
<Label Grid.Column="2" Text="{Binding Timer}" Style="{StaticResource StatusLabel}" />
</Grid>
Is it possible to specify that all labels inside the Grid using the StaticResource called StatusLabel without having to add that to each label?
Solution
There are explicit or implicit global styles.
Currently you are using an explicit style since you are defining a key for it and assigning them on each Label via their Style parameter.
<Style x:Key="StatusLabel" TargetType="Label">
~~~
</Style>
You can define an implicit style and thus ALL labels will receive that style, just do not define a key for it and do not manually assign the Style parameter
<Style TargetType="Label">
~~~
</Style>
You can then override individual implicit label's style via an explicit one.
So if the majority of your Labels are "StatusLabel" style, define that as the implicit style and override it when needed.
Re: Creating a Global Style in XAML
Note: Also you can define styles at the Page level and at the Control level and thus through Style inheritance can tweak individual style properties when needed.
Answered By - SushiHangover
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.