Silverlight-字体作为图标渲染太失真/像素化

时间:2018-07-27 02:55:11

标签: wpf xaml silverlight font-awesome

我目前将FontAwesome集成到了我的silverlight应用程序中。但是我注意到,在运行时实际上是像素化

Image

<!-- RadButton (via custom Button) -->
<Style TargetType="controls:Button" x:Key="DefaultRadButtonStyle">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Foreground" Value="{StaticResource DefaultColorBrush}" />
    <Setter Property="MouseOverStyle" Value="{StaticResource DefaultButtonMouseOverBorder}" />
    <Setter Property="FocusStyle" Value="{StaticResource DefaultButtonFocusBorder}" />
    <Setter Property="BorderBrush" Value="{StaticResource LineColorBrush}" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="FontFamily" Value="{StaticResource OpenSans-Regular}" />
    <Setter Property="Height" Value="{StaticResource CaptureGridRowHeightNumber}" />
    <Setter Property="Padding" Value="8, 0, 8, 1" />
    <Setter Property="FontSize" Value="13" />
    <Setter Property="Template">

用法:

<controls:Button
    Style="{StaticResource IconButtonStyle}"
    Command="{Binding RefreshCommand}">    
    <TextBlock Text="{StaticResource RefreshIcon}" Style="{StaticResource FontAwesomeTextBlockStyle}"/>
</controls:Button>

2 个答案:

答案 0 :(得分:1)

显然这是一个黑客

<Style x:Key="BaseFontAwesomeTextBlockStyle" TargetType="TextBlock">
    <Setter Property="FontSize" Value="16"/>
    <Setter Property="Foreground" Value="{StaticResource DefaultColorBrush}"/>
    <Setter Property="RenderTransform">
        <Setter.Value>
            <RotateTransform Angle="0.001"/>
        </Setter.Value>
    </Setter>
</Style>

答案 1 :(得分:0)

我建议您使用Path而不是图像(如果您使用的是任何图像)。由于它是矢量路径,因此应基于父容器缩放,并且不会出现像素化问题(它比图像更快,并且使用的资源更少)。示例刷新图像,

<Path Stretch="Fill" Fill="#FF000000" Data="F1 M 38,20.5833C 42.9908,20.5833 47.4912,22.6825 50.6667,
      26.046L 50.6667,17.4167L 55.4166,22.1667L 55.4167,34.8333L 42.75,34.8333L 38,30.0833L 46.8512,
      30.0833C 44.6768,27.6539 41.517,26.125 38,26.125C 31.9785,26.125 27.0037,30.6068 26.2296,
      36.4167L 20.6543,36.4167C 21.4543,27.5397 28.9148,20.5833 38,20.5833 Z M 38,49.875C 44.0215,
      49.875 48.9963,45.3932 49.7703,39.5833L 55.3457,39.5833C 54.5457,48.4603 47.0852,55.4167 38,
      55.4167C 33.0092,55.4167 28.5088,53.3175 25.3333,49.954L 25.3333,58.5833L 20.5833,
      53.8333L 20.5833,41.1667L 33.25,41.1667L 38,45.9167L 29.1487,45.9167C 31.3231,48.3461 34.483,
      49.875 38,49.875 Z "/>