I am working on a MAUI windows application. I made a resource directory file for font.xaml in Resources\Styles and configured it in App.xaml.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ABC.Resources.Styles.Fonts">
<x:Double x:Key="FontMicro">10</x:Double>
<x:Double x:Key="FontSmall">14</x:Double>
<x:Double x:Key="FontMedium">17</x:Double>
<x:Double x:Key="FontLarge">24</x:Double>
<x:Double x:Key="FontHeader">32</x:Double>
<x:Double x:Key="FontTitle">28</x:Double>
<x:Double x:Key="FontSubtitle">22</x:Double>
<x:Double x:Key="FontCaption">12</x:Double>
<x:Double x:Key="FontBody">16</x:Double>
<x:Double x:Key="FontExtraLarge">70</x:Double>
</ResourceDictionary
I want to use this key in my application. I want to utilize it in a custom control. Can I directly use a static resource with a key?
<controls:ImageButtonControl Grid.Column="1"
CustomImageSource="white_200.png"
CustomText="STRENGTH
TEST"
CustomFontSize="{StaticResource FontExtraLarge}"
HeightRequest="250"
Command="{Binding OnStrengthTestPageCommand}"/>
My Custom control.
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ABC.Pages.Controls.ImageButtonControl"
x:Name="imageButtonControl">
<ContentView.Content>
<Grid>
<ImageButton Source="{Binding CustomImageSource, Source={x:Reference imageButtonControl}}"
HorizontalOptions="Center"
VerticalOptions="Center"
BackgroundColor="Transparent"
BorderWidth="0"
Clicked="ImageButtonControl_Clicked"
Command="{Binding Command, Source={x:Reference imageButtonControl}}"/>
<Label Text="{Binding CustomText, Source={x:Reference imageButtonControl}}"
HorizontalOptions="Center"
VerticalOptions="Center"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
TextColor="Black"
InputTransparent="True"
FontSize="{Binding CustomFontSize, Source={x:Reference imageButtonControl}}"
CharacterSpacing="{Binding CustomCharacterSpacing, Source={x:Reference imageButtonControl}}"
FontFamily="{Binding CustomFontFamily, Source={x:Reference imageButtonControl}}"
FontAttributes="{Binding CustomFontAttribute, Source={x:Reference imageButtonControl}}"/>
</Grid>
</ContentView.Content>
</ContentView>
Is it necessary to define the target type (in my case, Label) and define all the fonts in Style.xaml like code below? I don't want to create a different style just to set a font size.
<Style TargetType="Label" x:Key="FontExtraLarge">
<Setter Property="FontSize" Value="70" />
</Style>
I also tried DynamicResource, which is also not working.

App.xaml, referenceFonts.xamlbeforeStyles.xamlto ensureStaticResourceandDynamicResourcework correctly. You may have aFonts.xaml.cs, but it isn’t necessary.App.xamland I would like an answer to why you appear to have a code-behind for yourfont.xaml.