我有一个WPF应用程序,用户界面应该被缩放,这样如果窗口变大,它应该变得更大。在其中一个对话框中,我需要向用户呈现一些项目列表,用户应该点击其中一个。该列表将包含1到约15-20个项目。我希望每个单独项目的字体大小与列表中其他项目的字体大小相同,但同时我希望如果窗口变大,则字体大小也会增加。
如果应用程序启动并且窗口被放大,一切都看起来很好。如果窗口宽度减小,文本“Test Longer String”的字体大小会变小,但“T”和“Test”的字体大小保持不变。我明白为什么会发生这种情况 - 视图框将内容缩放到其最大尺寸。我想知道的是我应该使用什么方法来解决这个问题。
我不想给控件指定特定的字体大小,因为有些人会在低分辨率屏幕上运行此应用程序,例如640x480,而其他人则会使用更大的宽屏幕。
编辑:
我尝试将代码修改为以下内容:
目前,我的测试代码如下所示。
<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>
但是随着按钮的尺寸增加,边框也会增加,因此在大屏幕上,按钮边框变得很宽。