I have following button in my Xamarin Forms application
<Button
Grid.Column="1"
Grid.Row="0">
<Button.ImageSource>
<FontImageSource Glyph="" FontFamily="{StaticResource IconFont}" Color="{StaticResource BaseColor}"/>
</Button.ImageSource>
</Button>
where IconFont
is:
<OnPlatform x:TypeArguments="x:String" x:Key="IconFont">
<On Platform="Android" Value="materialdesignicons-webfont.ttf#Material design" />
<On Platform="iOS" Value="Material Design Icons" />
</OnPlatform>
Everything is working fine. Now, because all of my icons are in materialdesignicons-webfont
and I will never use different icons I decided to move entire styling to App.xaml. I would like to set default properties like that:
<Style TargetType="FontImageSource">
<Setter Property="FontFamily" Value="{StaticResource IconFont}" />
<Setter Property="Color" Value="{StaticResource BaseColor}" />
</Style>
And use button by passing glyph only.
<Button
Grid.Column="1"
Grid.Row="0">
<Button.ImageSource>
<FontImageSource Glyph=""/>
</Button.ImageSource>
</Button>
For some reasons Icon is not rendered without specifying FontFamily
and Color
directly in FontImageSource
. Am I missing something?
Is there some way to call my button in simpler way? F.e.
<Button
Grid.Column="1"
Grid.Row="0"
MDGlyph="" />
For some reasons Icon is not rendered without specifying FontFamily and Color directly in FontImageSource. Am I missing something? Is there some way to call my button in simpler way? F.e. <Button Grid.Column="1" Grid.Row="0" MDGlyph="" /> Unfortunately it is not possible to style a FontImageSource currently.
This allows us to diverge from inherited, universal, and element styles globally. For example, all of our <h2> elements may be styled, by default, with a 2.25rem font-size:
Create a global style in XAML. By default, all Xamarin.Forms applications created from a template use the App class to implement the Application subclass. To declare a Style at the application level, in the application's ResourceDictionary using XAML, the default App class must be replaced with a XAML App class and associated code-behind.
Global Styles in Xamarin.Forms. Styles can be made available globally by adding them to the application's resource dictionary. This helps to avoid duplication of styles across pages or controls.
Unfortunately it is not possible to style a FontImageSource
currently. However, there is a github issue requesting this capability.
have you tried this:
<Style x:Key="ButtonWithFontImageSource" TargetType="Button">
<Setter Property="ImageSource">
<FontImageSource
FontFamily="{StaticResource FontIcons}"
Glyph="{DynamicResource IconText}">
</FontImageSource>
<Setter>
</Style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With