我将我的页面设计为4:3可扩展,我希望我的网格可以在任何屏幕上缩放到4:3。
例如,在1900x1200上,我的网格将扩展到1600x1200,并且我的网格每侧都有150px。我怎么能设法有这种行为?
我从以下几行开始:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="1024*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="768*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1" Grid.Column="1" Name="my_grid" />
</Grid>
但我不知道如何管理4:3的事情。我想强迫我的网格延伸,直到它具有最高的4:3分辨率,然后让两侧的自由空间。
你认为我只能在WPF中设法做到这一点吗?
由于
答案 0 :(得分:1)
您可以使用ViewBox控件。像您一样设计您的XAML并将其放入其中。 ViewBox将缩放以使内容适合可用大小。它不会调整内容的大小,因此所有内容(比率,宽度等)都将保持不变。
请参阅http://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox.aspx
答案 1 :(得分:0)
感谢Sascha,我做了:
<Viewbox Name="grid_jeu" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1" >
<MyControl Name="my_grid" />
</Viewbox>
我的控件是这样设计的:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32" MaxHeight="32"/>
<RowDefinition Height="72" MaxHeight="72"/>
<RowDefinition Height="10" MaxHeight="10"/>
<RowDefinition Height="*"/>
<RowDefinition Height="20" MaxHeight="20"/>
<RowDefinition Height="90" MaxHeight="90"/>
<RowDefinition Height="32" MaxHeight="32"/>
</Grid.RowDefinitions>
</Grid>
我希望只有一行和一列可扩展。正如你所看到的,我试图把&#34; MaxHeight&#34;和&#34; MaxWidth&#34;避免我的行扩展,但它不起作用。当我启动我的应用程序时,我的309px列可以扩展到420.