【发布时间】:2010-12-14 23:14:05
【问题描述】:
我有一个 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>
如果应用程序启动并且窗口变宽,一切看起来都正常。如果窗口宽度减小,文本Test Longer String 的字号变小,但T 和Test 的字号保持不变。我确实理解为什么会发生这种情况 - 视图框会将内容缩放到最大尺寸。我想知道的是我应该用什么方法来解决这个问题。
我不想为控件指定特定的字体大小,因为有些人会在 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>
但是随着按钮边框尺寸的增加,在大屏幕上,按钮边框变成一厘米宽。
【问题讨论】:
-
对我来说很好用:/ i.imgur.com/GXo14Vb.gifv
标签: wpf user-interface scaling font-size