我有一个WPF应用程序,其中用户界面应该缩放,以便它应该变大,如果窗户变大。在其中一个对话框中,我需要向用户提供一个项目列表,用户应该点击其中的一个。该列表将包含从1到大约15-20项。我希望每个单独项目的字体大小与列表中其他项目的字体大小一样大,但同时我希望字体大小在窗口变大时增加。WPF字体缩放
目前,我的测试代码如下所示。
<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>
但与按钮边框的大小在大屏幕上增加为好,这样,按钮边框变成厘米宽。
我已更新我的帖子。请参阅“编辑”。简而言之,如果我使用TextBlock而不是Button,则会松开“Button”-user界面(点击效果等)。如果我使用按钮并将其放置在Viewbox内部,则整个按钮(包括其边框)将被调整大小。仅仅因为程序最大化,我不需要1cm的按钮边框。 – Martin 2009-11-10 12:28:37