如何在wpf c#中缩放非内置/自定义字体

本文关键字:内置 自定义 字体 缩放 wpf | 更新日期: 2023-09-27 18:16:42

我目前正试图使一个程序,有一种启动屏幕踢到实际程序本身之前。我决定在程序中使用wpf,因此,启动屏幕必须用XAML编写。我有点掌握了它的诀窍,但我在尝试缩放从互联网上下载的字体时遇到了一个问题。似乎缩放只适用于内置和/或系统字体。有什么办法能让我把它放大吗?每次我尝试将其放入viewbox中时,它都会缩小所有内容。我试着用Calibri替换掉所有的文字,看看是否能解决这个问题,结果确实解决了。然而,要明确的是,我不想使用Calibri或任何其他内置字体,除非它真的"干净"。如果有人想知道,这个字体叫做Gidole。谢谢。下面是XAML代码:

<Window x:Name="StartPage" x:Class="ModernBoard.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ModernBoard"
        mc:Ignorable="d"
        Title="ModernBoard Welcome Page" ShowInTaskbar="False" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Background="#FF191919" Foreground="#FFE6E6E6" HorizontalAlignment="Center" VerticalAlignment="Center" ScrollViewer.VerticalScrollBarVisibility="Disabled" FontFamily="Gidole" SnapsToDevicePixels="True" Height="260.301" Width="653.627" FontStretch="Expanded">
    <Viewbox HorizontalAlignment="Left" Height="231" VerticalAlignment="Top" Width="648" Stretch="None">
        <Grid>
            <Label x:Name="WelcomeTo" Content="Welcome to" HorizontalAlignment="Left" Margin="38,27,0,0" VerticalAlignment="Top" Width="82" Height="27" FontFamily="Gidole" FontWeight="Bold" Foreground="#FFE6E6E6"/>
            <Label x:Name="Modern" Content="Modern" HorizontalAlignment="Left" Margin="37,36,0,0" VerticalAlignment="Top" Width="356" Height="120"  FontSize="90" Foreground="#FFE6E6E6" FontFamily="Gidole" FontWeight="Thin"/>
            <Label x:Name="Board" Content="Board" HorizontalAlignment="Left" Margin="336,36,0,0" VerticalAlignment="Top" Width="265" Height="120"  FontSize="90" Foreground="#FFE6E6E6" FontFamily="Gidole" FontWeight="Bold"/>
            <Button x:Name="New" Content="New Board" HorizontalAlignment="Left" Margin="44,135,0,0" VerticalAlignment="Top" Width="272" FontWeight="DemiBold" Foreground="#FFE6E6E6" Background="#2c406e" BorderThickness="0" Height="24"/>
            <Button x:Name="Open" Content="Open Board" HorizontalAlignment="Left" Margin="329,135,0,0" VerticalAlignment="Top" Width="272" FontWeight="DemiBold" Foreground="#FFE6E6E6" Background="#2c406e" BorderThickness="0" Height="24"/>
            <Button x:Name="Import" Content="Import File" HorizontalAlignment="Left" Margin="44,168,0,0" VerticalAlignment="Top" Width="557" FontWeight="DemiBold" Foreground="#FFE6E6E6" Background="#2c406e" BorderThickness="0" Height="24"/>
        </Grid>
    </Viewbox>
</Window>

这是预览的截图:预览

程序运行时的样子如下:

提前感谢,

Alex Fanat

如何在wpf c#中缩放非内置/自定义字体

您可以通过简单地在'Welcome To'标签上指定FontSize属性来'缩放'字体。你可能还想考虑删除Width/Height属性,否则你会看到标签文本被裁剪。

问题出在我安装字体的方式上;已安装但未正确加载。