xamarin.forms - FontImageSource 属性的全局样式

标签 xamarin.forms

我的 Xamarin Forms 应用程序中有以下按钮

    <Button
        Grid.Column="1"
        Grid.Row="0">
        <Button.ImageSource>
            <FontImageSource Glyph="&#xF072;" FontFamily="{StaticResource IconFont}" Color="{StaticResource BaseColor}"/>
        </Button.ImageSource>
    </Button>   
哪里IconFont是:
    <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>
一切正常。现在,因为我所有的图标都在 materialdesignicons-webfont我永远不会使用不同的图标,我决定将整个样式移动到 App.xaml。我想设置这样的默认属性:
    <Style TargetType="FontImageSource">
        <Setter Property="FontFamily" Value="{StaticResource IconFont}" />
        <Setter Property="Color" Value="{StaticResource BaseColor}" />
    </Style>
并仅通过传递字形来使用按钮。
    <Button
        Grid.Column="1"
        Grid.Row="0">
        <Button.ImageSource>
            <FontImageSource Glyph="&#xF072;"/>
        </Button.ImageSource>
    </Button>   
  • 由于某些原因,如果不指定 FontFamily 就不会呈现图标和 Color直接在FontImageSource .我错过了什么吗?
  • 有没有办法以更简单的方式调用我的按钮? F.e.

  •     <Button
            Grid.Column="1"
            Grid.Row="0"
            MDGlyph="&#xF072;" />
    

    最佳答案

    不幸的是,无法设置 FontImageSource 的样式目前。但是,有一个 github issue requesting this capability .

    关于xamarin.forms - FontImageSource 属性的全局样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58682824/

    相关文章:

    F# ViewModel 未通过 XAML 中的 BindingContext 实例化

    c# - 如何创建一个项目来为支持 iOS、Android 和 UWP 的 Xamarin Forms 创建 Nuget 包?

    c# - xamarin.forms 中的应用内购买

    c# - 如何 : convert unicode character representation in string to the actual unicode character

    Xamarin.Forms Prism 从导航堆栈中删除 View

    xamarin - 如何将 Hex 或 RGB 颜色分配给 Android Converter 中的 MvxColor

    c# - 如何在 Xamarin.Forms 中重用父 ContentView 中定义的样式

    c# - xamarin 形式的侧边栏抽屉

    xamarin - 在内容页 XAMARIN FORMS 中调用 onresumo() 方法

    c# - Xamarin 表格 : Android: Toast Notifications Clicked