WPF字体缩放

Mar*_*tin 8 wpf user-interface scaling font-size

我有一个WPF应用程序,其中应缩放用户界面,以便在窗口变大时它应该变大.在其中一个对话框中,我需要向用户显示项目列表,用户应单击其中一个.该列表将包含1到15-20个项目.我希望每个项目的字体大小与列表中其他项目的字体大小一样大,但同时我希望在窗口变大时字体大小增加.

目前,我的测试代码如下所示.

<Window x:Class="WpfApplication4.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:WpfApplication4"
    Title="Window1" Height="480" Width="640">


    <ScrollViewer>

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="30*" MinHeight="30"/>
                <RowDefinition Height="30*" MinHeight="30"/>
                <RowDefinition Height="30*" MinHeight="30"/>
            </Grid.RowDefinitions>

            <Button Grid.Row="0" MaxHeight="100"><Viewbox><TextBlock>T</TextBlock></Viewbox></Button>
            <Button Grid.Row="1" MaxHeight="100"><Viewbox><TextBlock>Test</TextBlock></Viewbox></Button>
            <Button Grid.Row="2" MaxHeight="100"><Viewbox><TextBlock>Test Longer String</TextBlock></Viewbox></Button>

        </Grid>

    </ScrollViewer>

</Window>
Run Code Online (Sandbox Code Playgroud)

如果应用程序启动并且窗口变宽,则一切看起来都正常.如果窗口宽度减小时,文本的字体大小Test Longer String变小,但的字体大小TTest保持相同.我明白为什么会发生这种情况 - 视图框会将内容缩放到最大尺寸.我想知道的是我应该用什么方法来解决这个问题.

我不想给控件特定的字体大小,因为有些人会在640x480这样的低分辨率屏幕上运行它,而其他人会使用更大的宽屏.

编辑:

我试图将我的代码修改为以下内容:

<ScrollViewer>
    <Viewbox>
        <ItemsControl>
            <Button>Test 2</Button>
            <Button>Test 3</Button>
            <Button>Test 4 afdsfdsa fds afdsaf</Button>
            <Button>Test 5</Button>
            <Button>Test 5</Button>
            <Button>Test 5</Button>
            <Button>Test 5</Button>
            <Button>Test 5</Button>
        </ItemsControl>
    </Viewbox>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

但随着按钮边框的大小也增加,因此在大屏幕上,按钮边框变为厘米宽.

Pie*_*eed 0

试试这个:像其他时候一样渲染文本项:

  • TextBlocks 包含在“ItemsControl”中吗?
  • ListBox

将整个 shebang 放入 a 中ViewBox,并将其设置为适合您需要的比例。寻找水平、垂直或组合缩放属性。