网格不覆盖UWP应用中的所有屏幕

时间:2016-03-19 00:59:54

标签: xaml win-universal-app

为什么我的网格没有覆盖所有屏幕,我该如何解决?在设计师看来它应该覆盖屏幕的所有宽度,但实际上留下了很大的空间。

 <Grid Background="GreenYellow">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />

    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="200"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>


</Grid>

这段代码只是一个剪辑,但即使是孩子们的空间也是不同的尺寸。

修改1:

  

根据路易斯C.回答我得到了相同的结果左边的空白空间:

still a blank space to the left

我找到了一个奇怪的解决方法来实现我想要的目标:

 <Grid  Background="Yellow">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="200"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Grid Grid.Row="0">
        <TextBlock Text="This is a very large text that only is used to strech all the childrens to the infinite. This is a very large text that only is used to strech all the childrens to the infinite. This is a very large text that only is used to strech all the childrens to the infinite. This is a very large text that only is used to strech all the childrens to the infinite. This is a very large text that only is used to strech all the childrens to the infinite" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
        <Button Content="Black" Background="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
    </Grid>


    <Button Grid.Row="1" Content="Black" Background="Gray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
    <Button Grid.Row="2" Content="Black" Background="Blue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />

</Grid>

结果是:

Result with workaround

仍然是解决问题的一种非常奇怪的方式。

完整代码

如您所见,我在GridView上使用SplitView,在SplitViewContent内的Frame上加载Pages(就像上面提到的问题一样)。使用TextBlock作为孩子的其他页面覆盖了我想要的整个屏幕。 SplitView的代码是:

<Page
x:Class="MyProject.ViewModels.HomePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyProject.ViewModels"
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}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <RelativePanel>
        <Button Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="&#xE700;" FontSize="36" Click="HamburgerButton_Click" Background="LightGray"/>
        <!--<Button Name="BackButton" FontFamily="Segoe MDL2 Assets" Content="&#xE72B;" FontSize="36" Visibility="Visible" Background="LightGray"/>-->
        <CommandBar Name="Bar" RelativePanel.AlignRightWithPanel="True" ClosedDisplayMode="Compact" RelativePanel.RightOf="HamburgerButton" Visibility="Visible" Background="LightGray" IsOpen="False" IsSticky="True" >
            <CommandBar.Content>
                <TextBlock Name="BarTitle" Text="Title" FontSize="24" Margin="24,8,0,12" HorizontalAlignment="Center" VerticalAlignment="Center" />

            </CommandBar.Content>
        </CommandBar>
    </RelativePanel>
    <SplitView Name="MySplitView" 
               Grid.Row="1" 
               DisplayMode="Overlay" 
               OpenPaneLength="200" 
               CompactPaneLength="56" 
               HorizontalAlignment="Left">
        <SplitView.Pane>
            <ListBox SelectionMode="Single" 
                     Name="IconsListBox" 
                     SelectionChanged="IconsListBox_SelectionChanged">
                <ListBoxItem Name="SymbolsListBoxItem">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="x" Width="36" Height="36" HorizontalAlignment="Center" VerticalAlignment="Center"> </Image>
                        <TextBlock x:Uid="Symbols" Text="[Symbols]"  FontSize="24" Margin="20,0,0,0" />
                    </StackPanel>
                </ListBoxItem>                 
            </ListBox>
        </SplitView.Pane>
        <SplitView.Content >
            <Frame Name="FrameHolder"></Frame>
        </SplitView.Content>
    </SplitView>
    <Frame Name="HomePageFrame" >
        <!-- Frame not used by now-->
    </Frame>

</Grid>

完整的代码页代码段(包含更多子代),结果与右侧大空白空格相同:

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

<Page.Resources>
    <Style TargetType="ListView" x:Key="myListViewStyle">
        <Setter Property="AllowDrop" Value="False" />
        <Setter Property="CanReorderItems" Value="False" />
        <Setter Property="Width" Value="36"/>
        <Setter Property="Height" Value="140"/>
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="Padding" Value="0,4,0,0"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />

        <Setter Property="BorderBrush" Value="White" />
        <Setter Property="BorderThickness" Value="1" />
    </Style>

    <Style TargetType="TextBlock" x:Key="SymbolViewer">
        <Setter Property="FontFamily" Value="/Fonts/etc"/>
        <Setter Property="FontSize" Value="30" />
        <Setter Property="Padding" Value="8"/>
        <Setter Property="TextAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
    </Style>


    <LinearGradientBrush x:Key="GradBackground" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="LightGray" Offset="0"/>
        <GradientStop Color="White" Offset=".5"/>
        <GradientStop Color="LightGray" Offset="1"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="ItemGradBackground" EndPoint="0.5,1" StartPoint="0.5,0">

        <GradientStop Color="White" Offset="0"/>
        <GradientStop Color="White" Offset=".5"/>
        <GradientStop Color="LightGray" Offset="1"/>
    </LinearGradientBrush>
</Page.Resources>



<!-- Spinners  -->


<StackPanel Background="AliceBlue" HorizontalAlignment="Stretch" Padding="0">
    <StackPanel Background="{StaticResource GradBackground}" >
        <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" >

            <ListView Name="Uno" ItemsSource="{x:Bind UnoItems}" Style="{StaticResource myListViewStyle}" BorderBrush="White" 
                          BorderThickness="2" IsItemClickEnabled="True" ItemClick="Uno_ItemClick">

                <ListView.ItemTemplate >
                    <DataTemplate x:DataType="data:Thingy">
                        <TextBlock Text="{x:Bind Symbol}" FontFamily="/Fonts/etc"></TextBlock>
                    </DataTemplate>

                </ListView.ItemTemplate>

            </ListView>

            <!-- Not user interactive-->
            <TextBlock Text="0" Width="36" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" ></TextBlock>

            <!-- Spinner 2 -->
            <ListView Name="Dos" ItemsSource="{x:Bind DosItems}" Style="{StaticResource myListViewStyle}"
                          IsItemClickEnabled="True" ItemClick="Dos_ItemClick">

                <ListView.ItemTemplate >
                    <DataTemplate x:DataType="data:Thingy">
                        <TextBlock Text="{x:Bind Symbol}" ></TextBlock>
                    </DataTemplate>

                </ListView.ItemTemplate>

            </ListView>

            <ListView Name="Tres" ItemsSource="{x:Bind TresItems}" Style="{StaticResource myListViewStyle}">

                <ListView.ItemTemplate >
                    <DataTemplate x:DataType="data:Thingy">
                        <TextBlock Text="{x:Bind Symbol}" ></TextBlock>
                    </DataTemplate>

                </ListView.ItemTemplate>

            </ListView>
            <ListView Name="Cuatro" ItemsSource="{x:Bind TresItems}" Style="{StaticResource myListViewStyle}">

                <ListView.ItemTemplate >
                    <DataTemplate x:DataType="data:Thingy">
                        <TextBlock Text="{x:Bind Symbol}" ></TextBlock>
                    </DataTemplate>

                </ListView.ItemTemplate>

            </ListView>

            <ListView Name="Cinco" ItemsSource="{x:Bind DosItems}" Style="{StaticResource myListViewStyle}">

                <ListView.ItemTemplate >
                    <DataTemplate x:DataType="data:Thingy">
                        <TextBlock Text="{x:Bind Symbol}" ></TextBlock>
                    </DataTemplate>

                </ListView.ItemTemplate>

            </ListView>

            <ListView Name="Seiss" ItemsSource="{x:Bind TresItems}" Style="{StaticResource myListViewStyle}">

                <ListView.ItemTemplate >
                    <DataTemplate x:DataType="data:Thingy">
                        <TextBlock Text="{x:Bind Symbol}"></TextBlock>
                    </DataTemplate>

                </ListView.ItemTemplate>

            </ListView>
        </StackPanel>
    </StackPanel>


</StackPanel>

1 个答案:

答案 0 :(得分:0)

您只需删除没有高度的“RowDefinition”并将“Auto”行更改为“*”。

这样的事情:

<Grid Background="GreenYellow">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="200"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Button Grid.Row="0" Content="Black" Background="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
    <Button Grid.Row="1" Content="Black" Background="Gray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
    <Button Grid.Row="2" Content="Black" Background="Blue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />

</Grid>