简体   繁体   English

如何在Windows8中使应用适应多种分辨率

[英]How to adapt the app to multiple resolution in Windows8

I have the layout code below in xaml 我在xaml中有以下布局代码

<Grid>
   <StackPanel x:Name="TestStackPanel" Grid.Row="2" Orientation="Horizontal">
      <ScrollViewer x:Name="TestScrollViewer" Height="300" VerticalScrollBarVisibility="Auto">
         <GridView x:Name="TestGridView"
            Width="940"
            Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
            ItemTemplate="{StaticResource TestTemplate}"
            ItemsPanel="{StaticResource TestItemPanelTemplate}" 
            ItemContainerStyle="{StaticResource TestItemStyle}" 
            SelectionMode="None"                                  
            HorizontalAlignment="Left"/>
       </ScrollViewer>
       <Button x:Name="TestButton" Content="ClickMe" VerticalAlignment="Bottom" Margin="10,5,0,0" Click="TestButton_Click"/>
 </StackPanel>
</Grid>

This displays well in 1366*768 resolution, but if I change the resolution to 2560*1400, it couldn't displays as expected, I know it's certain, but how to adpat the layout to different resolutions? 这在1366 * 768的分辨率下可以很好地显示,但是如果我将分辨率更改为2560 * 1400,它就不能按预期显示,我知道这是肯定的,但是如何使布局适应不同的分辨率呢? I have tried to add a ViewBox to encapsulate the Grid, it works well in FullScreenLandScape view, but when I change the app to Snap view, the Grid displays in a samll space. 我试图添加一个ViewBox来封装Grid,它在FullScreenLandScape视图中运行良好,但是当我将应用程序更改为Snap视图时,Grid将显示在一个小空间中。

Anyone can help? 有人可以帮忙吗?

Register to the LayoutUpdated event at the UI element. 在UI元素上注册到LayoutUpdated事件。
And re-calculate the layout according to Window.Current.Bounds.Width . 然后根据Window.Current.Bounds.Width重新计算布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM