我有一個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