带ScroolViewer的UWP Grid RowSpan

时间:2016-04-24 16:17:17

标签: xaml win-universal-app uwp-xaml

如果您将此代码粘贴到新UWP应用程序的主页中(或查看第一张图片),您会发现橙色网格占用的空间超出了所需的空间(VerticalAlignment设置为顶部)。为了使其按预期工作,您必须将此网格的第2行高度设置为Auto(请参阅第2张图片)。问题是我想给第2行/最后一行提供额外的空间,而不是将它分配到所有行 将左侧列中的控件放在他们自己的网格中(显然,因为没有rowspan)但是我不能这样做,因为当屏幕缩小时,右列中的stackpanel会进入左列的一行内

第二个问题是,如果单击橙色/绿色/黄色空间,焦点将始终转到第一行的文本框(黄色)。

更新:两个问题都是在没有滚动查看器的情况下修复的,但我显然需要它。


<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
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}">
    <ScrollViewer Background="DarkGreen" VerticalScrollBarVisibility="Auto">
        <Grid Background="DarkOrange" Margin="10" VerticalAlignment="Top">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0" Background="Yellow">
                <TextBlock Text="Title" />
                <TextBox Margin="20" />
            </StackPanel>
            <Grid Grid.Row="1" Background="DeepPink" VerticalAlignment="Top">
                <ListView Margin="10" VerticalAlignment="Top">
                    <ListView.Items>
                        <TextBlock Text="Item1" />
                    </ListView.Items>
                </ListView>
            </Grid>
            <StackPanel Grid.Column="1" Grid.RowSpan="2" Background="Blue" VerticalAlignment="Top">
                <StackPanel>
                    <TextBlock Text="Title1" />
                    <GridView Margin="0,10,0,0">
                        <GridView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="4" />
                            </ItemsPanelTemplate>
                        </GridView.ItemsPanel>
                        <GridView.Items>
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                        </GridView.Items>
                    </GridView>
                </StackPanel>
                <StackPanel>
                    <TextBlock Text="Title2" />
                    <GridView Margin="0,10,0,0">
                        <GridView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="4" />
                            </ItemsPanelTemplate>
                        </GridView.ItemsPanel>
                        <GridView.Items>
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                            <Rectangle Width="80" Height="80" Fill="White" />
                        </GridView.Items>
                    </GridView>
                </StackPanel>
            </StackPanel>
        </Grid>
    </ScrollViewer>
</Grid>

rowspan

1 个答案:

答案 0 :(得分:0)

我找到了解决方法。由于第一行不会扩展或更改,我将第一行的MaxHeight属性设置为等于行的实际高度。

对于第二个问题,请将滚动查看器的IsTabStop属性设置为True,如下所述:
https://social.msdn.microsoft.com/Forums/windowsapps/en-US/32e026dd-8338-4c19-a7d6-1bb8797044b3/first-input-control-in-the-scroll-viewer-is-always-getting-focused?prof=required