Windows Phone 8.1 适用于所有分辨率的自适应应用

Windows Phone 8.1 Adaptive app for all resolutions

我希望之前没有人问过这个问题,我到处都找不到简单的解决方案... 我正在开发一个简单的 windows phone 8.1 音板,但如果分辨率大于 VXGA,则网格和按钮太小且位置错误。我读到这个:Taking Advantage of Large-Screen Windows Phones 但是我没看懂。

有谁知道如何帮助我吗?

您需要实现您的 xaml 视觉状态。这些视觉状态具有自适应触发器(如显示分辨率)和设置器(例如,如果自适应触发器触发,则将按钮高度设置为 50)。 就像这样:

<Page
x:Class="VisualStates.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:VisualStates"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup>
            <VisualState>
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="0"></AdaptiveTrigger>
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="AdaptiveButton.Width" Value="80"></Setter>
                </VisualState.Setters>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Button x:Name="AdaptiveButton" VerticalAlignment="Center" HorizontalAlignment="Center" Width="0">Test</Button>
</Grid>

如果没有视觉状态,自适应按钮的宽度将为 0,但由于视觉状态,它的宽度设置为 80。 当然,这是一个不实际的示例,您应该为 visual studio 使用 blend,因为它甚至可以为您提供 ui 来简单地实现这些视觉状态。但在练习之前,您应该 google "visualstatemanager class" 并搜索更多示例。 编辑: 例如,您还可以在 pageloaded 方法中检查 window 宽度和高度,然后更改属性,例如:

double displaywidth = App.Current.Host.Content.ActualWidth;
if(displaywidth >= 300) {}//set local variable display width and than do sth