我们使用网格在75px的顶部布置导航栏,下面的内容区域应该占据高度的其余部分(我们正在使用框架导航方法)。
内容部分虽然被压缩到100px并且添加了一个水平滚动条。我添加了文本换行,但没有帮助。我在内容部分周围放置了一个边框,我可以看到它没有占据导航栏下方的整个空间,这应该是所有屏幕的剩余部分。
代码如下:
<UserControl
x:Class="DocRupert.Ui.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:uriMapper="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
xmlns:dataControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
xmlns:login="clr-namespace:DocRupert.Ui.LoginUI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot" Style="{StaticResource LayoutRootGridStyle}" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="75" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Style="{StaticResource NavigationOuterGridStyle}" Grid.Row="0">
<Border>
<Grid x:Name="NavigationGrid" Style="{StaticResource NavigationGridStyle}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="35" />
</Grid.RowDefinitions>
<Border x:Name="BrandingBorder" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Style="{StaticResource BrandingBorderStyle}">
<StackPanel x:Name="BrandingStackPanel" Style="{StaticResource BrandingStackPanelStyle}">
<ContentControl Style="{StaticResource LogoIcon}"/>
<TextBlock x:Name="ApplicationNameTextBlock" Style="{StaticResource ApplicationNameStyle}" Text="{Binding Strings.ApplicationName, Source={StaticResource ApplicationResources}}"/>
</StackPanel>
</Border>
<Border x:Name="LinksBorder" Grid.Column="1" Grid.Row="0" Style="{StaticResource LinksBorderStyle}" VerticalAlignment="Top">
<StackPanel x:Name="LinksStackPanel" Style="{StaticResource LinksStackPanelStyle}">
<HyperlinkButton x:Name="MenuHome" Style="{StaticResource LinkStyle}" NavigateUri="/Home" TargetName="ContentFrame" Content="{Binding Path=Strings.HomePageTitle, Source={StaticResource ApplicationResources}}"/>
<Rectangle x:Name="Divider1" Style="{StaticResource DividerStyle}"/>
<HyperlinkButton x:Name="MenuAboutUs" Style="{StaticResource LinkStyle}" NavigateUri="/About" TargetName="ContentFrame" Content="{Binding Path=Strings.AboutPageTitle, Source={StaticResource ApplicationResources}}"/>
</StackPanel>
</Border>
<Border Grid.Column="1" Grid.Row="1">
<StackPanel x:Name="AuthenticationStatusPanel" Style="{StaticResource AuthenticationStatusPanelStyle}">
<login:LoginStatus/>
</StackPanel>
</Border>
</Grid>
</Border>
</Grid>
<Border x:Name="ContentBorder" Grid.Row="1" Style="{StaticResource ContentBorderStyle}" VerticalAlignment="Top">
<navigation:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}" Source="/Home" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed">
<navigation:Frame.UriMapper>
<uriMapper:UriMapper>
<uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
</uriMapper:UriMapper>
</navigation:Frame.UriMapper>
</navigation:Frame>
</Border>
</Grid>
</UserControl>
[编辑] - 添加主页XAML 这是加载到框架中的主页的XAML:
<Grid x:Name="LayoutRoot">
<ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">
<StackPanel x:Name="ContentStackPanel" Style="{StaticResource ContentStackPanelStyle}">
<TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}"
Text="{Binding Path=Strings.HomePageTitle, Source={StaticResource ApplicationResources}}"/>
<TextBlock TextWrapping="Wrap" Text="Nulla tincidunt, arcu quis ultrices viverra, sapien enim gravida massa, aliquet mollis dolor neque in orci. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent blandit diam quis massa iaculis ut lobortis dui ornare. Morbi pulvinar rutrum justo, ut lacinia elit feugiat bibendum. Duis pharetra dictum mauris sit amet egestas. Suspendisse potenti. Vestibulum posuere velit a enim sollicitudin varius interdum erat scelerisque. Pellentesque blandit felis a diam euismod adipiscing. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vestibulum nunc erat; rutrum vel mattis tincidunt, tincidunt id leo. Suspendisse a accumsan urna. Etiam felis nisi, vulputate vel volutpat nec, ultrices nec quam. Maecenas viverra, sapien consequat pharetra vehicula, est erat pretium ipsum, at tempus nunc justo a mauris. Quisque ac auctor eros.
Sed id sollicitudin ligula. Phasellus dictum mauris vel libero imperdiet dictum. Donec bibendum, magna sit amet vestibulum hendrerit, mi turpis tincidunt arcu, eget pellentesque mauris lacus luctus mi. Quisque id justo turpis. Curabitur sollicitudin massa fermentum nunc adipiscing tincidunt vitae non diam. Praesent venenatis aliquet orci sed tincidunt? Etiam tincidunt ligula nec felis dictum condimentum nec egestas urna. Pellentesque blandit diam quis lacus suscipit pharetra. Nunc diam ante, vestibulum ac bibendum venenatis, laoreet blandit eros. Proin eleifend felis velit, a varius leo. Aliquam erat volutpat. Maecenas varius nisl a arcu malesuada convallis. Vestibulum at ipsum turpis, nec pharetra ipsum.
Sed blandit ultrices pulvinar! Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris aliquam scelerisque sem sed tempor. Sed erat risus, tincidunt vitae pellentesque et, semper eu odio! Cras accumsan cursus urna a elementum. Vestibulum quam velit, sollicitudin sed posuere quis, ullamcorper ut purus. Pellentesque sollicitudin nibh vitae diam elementum eu convallis velit viverra. Maecenas convallis cursus porttitor. Pellentesque purus urna, ultricies sit amet tempor et, hendrerit at sem. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nunc in felis massa, ut congue leo. Maecenas in cursus massa!"></TextBlock>
<TextBlock>hello world</TextBlock>
</StackPanel>
</ScrollViewer>
</Grid>
答案 0 :(得分:1)
您在导航内容页面中使用了哪些GUI元素?我建议将Grid作为主GUI元素,并确保其拉伸以占用所有可用空间。为了确保您为所有页面正确执行此操作,我建议使用样式,如下所示:
<Style x:Key="NavigationContentGrid" TargetType="Grid">
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
导航根目录:
<Grid x:Name="LayoutRoot" Style="{StaticResource NavigationContentGrid}">
<ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">
...
</ScrollViewer>
</Grid>
另外,我建议您的LayoutRootGridStyle和NavigationOuterGridStyle样式都具有相同的VerticalAlignment&amp;设置HorizontalAlignment属性。