加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

xaml – Windows通用响应式设计重新定位

发布时间:2020-12-14 04:04:50 所属栏目:Windows 来源:网络整理
导读:所以,我刚刚开始使用 Windows应用程序,有一些我无法按照自己的意愿工作(可能是因为我找不到任何样本,而且Channel9视频没有覆盖我的情况). 从this article开始,我决定“重新定位”技术是适合我的应用程序从大屏幕移动到较小屏幕的技术. 我所做的是使用StackPa
所以,我刚刚开始使用 Windows应用程序,有一些我无法按照自己的意愿工作(可能是因为我找不到任何样本,而且Channel9视频没有覆盖我的情况).

从this article开始,我决定“重新定位”技术是适合我的应用程序从大屏幕移动到较小屏幕的技术.

我所做的是使用StackPanel并使用两个AdaptiveTriggers改变其方向(一个用于0宽度,另一个用于720,基于表here).

这种方法有效,但我会用一些丑陋的油漆编辑的截图来说明一些问题.

这就是当我处于BigScreen情况时会发生的情况,那里有足够的空间让A和B同时在同一行上.这里的问题是B应该占据剩余的全部宽度,覆盖所有蓝色部分.

第二个问题与调整大小有关.当没有足够的空间时,绿色部分会被切割而不是调整大小(您可以看到右侧边框消失).在使用StackPanel使布局响应之前,这没有发生.

最后,当我们处于SmallScreen情况时,方向变为垂直方向,我们遇到与第一个相同的问题:绿色部分的高度不会填满屏幕.

这是用于页面的XAML:

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

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="SmallScreen">
            <VisualState>
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="0"/>
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="StackPanel.Orientation" 
                            Value="Vertical"/>
                </VisualState.Setters>
            </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="BigScreen">
            <VisualState>
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="720"/>
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="StackPanel.Orientation" 
                            Value="Horizontal"/>
                    <Setter Target="Rect.Width" 
                            Value="200"/>
                        <Setter Target="Rect.Height" 
                            Value="Auto"/>
                    </VisualState.Setters>
            </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <StackPanel Orientation="Vertical"
                    Background="Blue"
                    x:Name="StackPanel">
            <Rectangle Fill="Red" 
                       Height="50"
                       x:Name="Rect"
                       Width="Auto"/>
            <ListView ItemsSource="{Binding Stuff}"
                      HorizontalAlignment="Stretch"
                      HorizontalContentAlignment="Stretch"
                      VerticalAlignment="Stretch"
                      Background="Green"
                      Width="Auto"
                      BorderBrush="DarkGreen"
                      BorderThickness="5"
                      Padding="5">
                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        <Setter Property="Margin" Value="0,5"/>
                    </Style>
                </ListView.ItemContainerStyle>
            </ListView>
        </StackPanel>
    </Grid>
</Page>

请注意,如果没有StackPanel,绿色部分将适合页面,覆盖所有可用区域.不幸的是,我无法找到更好的解决方案,因为没有样本告诉我们应该如何实现这种技术.我也尝试使用新的RelativePanel,但似乎AdaptiveTrigger的Setter不能与RelativePanel.RightOf这样的附加属性一起使用.

是否有人成功应用这种技术而不必使用代码隐藏?

编辑:

我使用一个包含2行和2列的Grid工作,使用AdaptiveTrigger将所有内容从行移动到列,反之亦然.

可以通过setter更改RelativePanel附加属性值.语法如下:
<Setter Target="SomeXAMLObject.(RelativePanel.RightOf)" Value="SomeOtherXAMLObject" />

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读