代码之家  ›  专栏  ›  技术社区  ›  Peter Perháč

在可能没有内容的网格中右对齐按钮-拉伸网格以始终填充页面

  •  3
  • Peter Perháč  · 技术社区  · 15 年前

    我对这件事失去了耐心。我正在开发一个WindowsPhone7应用程序,我不知道使用什么布局管理器来实现以下目标:

    An sketch of the desired page layout

    基本上,当我使用一个网格作为布局根时,我无法使网格扩展到电话应用程序页面的大小。当主内容区已满时,一切正常,按钮位于我希望它位于的位置。但是,如果页面内容很短,则网格的宽度只能容纳其内容,然后按钮(我非常希望保持在屏幕右边缘附近)从右边缘移动。

    如果我替换网格并对布局根使用垂直方向的堆栈面板,则按钮将位于我所需的位置,但内容区域将能够超出底边。所以,当我在主内容区域中放置一个装满项目的列表框时,它不会将其高度调整为完全在视图中,但是该列表框中的大多数项目只是在显示区域的底部边缘下呈现。

    HorizontalAlignment="Right" 但结果与网格相同,当内容区域中没有足够的内容(或标题较短)时,网格的大小也会缩小。

    那我该怎么做呢?


    ==编辑==

    <phone:PhoneApplicationPage 
        x:Name="categoriesPage"
        x:Class="CatalogueBrowser.CategoriesPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="PortraitOrLandscape"  Orientation="Portrait" 
        mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
        xmlns:ctrls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
        shell:SystemTray.IsVisible="True">
    
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" >
                    <TextBlock Text="Browsing:" 
                           Margin="10,10" 
                           Style="{StaticResource PhoneTextTitle3Style}" />
                    <TextBlock x:Name="ListTitle" 
                           Text="{Binding DisplayName}" 
                           Margin="0,10" 
                           Style="{StaticResource PhoneTextTitle3Style}" />
                </StackPanel>
                <Button Grid.Column="1"
                        x:Name="btnRefineSearch" 
                        Content="Refine Search" 
                        Style="{StaticResource buttonBarStyle}" 
                        FontSize="14" />
            </Grid>
    
            <Grid x:Name="ContentPanel" Grid.Row="1">
                <ListBox x:Name="CategoryList" 
                         ItemsSource="{Binding Categories}" 
                         Style="{StaticResource CatalogueList}" 
                         SelectionChanged="CategoryList_SelectionChanged"/>
            </Grid>
        </Grid>
    
    </phone:PhoneApplicationPage>
    

    这就是仿真器中具有上述XAML标记的页面的外观:

    alt text

    3 回复  |  直到 15 年前
        1
  •  3
  •   Matt Lacey    15 年前

    这能达到你想要的吗?

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
    
        <TextBox Grid.Column="0" Grid.Row="0" />
        <Button Content="Search" Grid.Column="1" Grid.Row="0" />
        <ScrollViewer Grid.Row="1" Grid.ColumnSpan="2"></ScrollViewer>
    </Grid>
    

    Grid 在默认页面/项目中使用name=“ContentPanel”。

        2
  •  2
  •   WiredPrairie    15 年前

    <phone:PhoneApplicationPage 
        x:Class="WindowsPhoneApplication1.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        shell:SystemTray.IsVisible="True">
    
        <!--LayoutRoot is the root grid where all page content is placed-->
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="CAPTION" VerticalAlignment="Center" />
                <Button Content="Button" Grid.Column="1" />
            </Grid>
    
            <!--ContentPanel - place additional content here-->
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            </Grid>
        </Grid>
    
    </phone:PhoneApplicationPage>
    
        3
  •  1
  •   Peter Perháč    15 年前

    谢谢你们的回复,他们帮我找到了单独页面下面的bug。为了在页面之间进行漂亮的页面翻转转换,我使用了从WP7示例中复制的样式。此样式设置PhoneApplicationFrame的模板时,垂直对齐和水平对齐(我相信默认设置为拉伸)被重写,因此由于此特殊的PhoneApplicationFrame模板,我的页面没有按通常预期的方式布局。

    干杯:-)