我正在尝试使用 Xaml 在网格上为 WinRT 应用程序获取滚动条。基本页面设置有一个用于顶部和中间部分的整体网格。在中间部分,我放置了另一个 2 行 2 列的网格。在该网格的第 1 列第 1 行内,我想在要显示的数据内放置一个带有另一个网格的边框,并在边框区域内有一个滚动条。
我已经为此绞尽脑汁了大约 3 天,断断续续地在网上搜索
我粗略地尝试了这两种方法,我认为应该可以,但不行。简化了,但文本框的网格有大约 30 个文本框网格要显示。
<Grid x:Name="PersonViewContent" Grid.Row="1">
<ScrollViewer
x:Name="MainScrollViewer"
Grid.Row="1"
ZoomMode="Disabled"
IsTabStop="False"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
Padding="0,0,0,20">
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="Auto" />
<ColumnDefinition
Width="*" />
</Grid.ColumnDefinitions>
<Border
BorderBrush="Black"
BorderThickness="5"
HorizontalAlignment="Left"
Width="500"
Margin="10,10,10,10"
VerticalAlignment="Top">
<ScrollViewer
x:Name="PersonScroller"
Margin="0"
FontFamily="Segoe UI"
FontSize="20"
IsHorizontalRailEnabled="true"
IsHorizontalScrollChainingEnabled="False"
IsDoubleTapEnabled="False"
IsHoldingEnabled="False"
IsRightTapEnabled="False"
IsTapEnabled="False">
<StackPanel
Margin="0"
Width="490"
HorizontalAlignment="Left">
<Grid
Height="250"
Margin="10,10,10,10"
VerticalAlignment="Bottom">
<Image
Source="{Binding Image}"
AutomationProperties.Name="{Binding ImageSourceSubtitle}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Stretch="{Binding ImageStretch}" />
<TextBlock
Text="{Binding Subtitle}"
Margin="0,180,0,0"
TextWrapping="Wrap"
Style="{StaticResource SubheaderTextStyle}"
MaxHeight="60"
FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
<Grid
Height="Auto">
<TextBlock
Text="Textblock"
Margin="5,10,0,0"
Style="{StaticResource BasicTextStyle}"
MaxHeight="60"
FontSize="20"
FontWeight="Bold" />
</Grid>
<Grid
Height="Auto">
<TextBlock
Text="Textblock: "
Margin="5,0,0,0"
Style="{StaticResource BasicTextStyle}"
MaxHeight="60"
FontSize="20" />
<TextBlock
Text="{Binding Name}"
Margin="152,0,0,0"
Style="{StaticResource BasicTextStyle}"
FontSize="20" />
</Grid>
<Grid
Height="Auto">
<TextBlock
Text="Textblock: "
Margin="5,0,0,0"
Style="{StaticResource BasicTextStyle}"
MaxHeight="60"
FontSize="20" />
<TextBlock
Text="{Binding Name}"
Margin="152,0,0,0"
Style="{StaticResource BasicTextStyle}"
FontSize="20" />
</Grid>
<Grid
Height="Auto">
<TextBlock
Text="Textblock: "
Margin="5,0,0,0"
Style="{StaticResource BasicTextStyle}"
MaxHeight="60"
FontSize="20" />
<TextBlock
Text="{Binding Name}"
Margin="152,0,0,0"
Style="{StaticResource BasicTextStyle}"
FontSize="20" />
</Grid>
<Grid
Height="Auto">
<TextBlock
Text="Textblock: "
Margin="5,0,0,0"
Style="{StaticResource BasicTextStyle}"
MaxHeight="60"
FontSize="20" />
<TextBlock
Text="{Binding Name}"
Margin="152,0,0,0"
Style="{StaticResource BasicTextStyle}"
FontSize="20" />
</Grid>
<Grid
Height="Auto">
<TextBlock
Text="Textblock: "
Margin="5,0,0,0"
Style="{StaticResource BasicTextStyle}"
MaxHeight="60"
FontSize="20" />
<TextBlock
Text="{Binding Name}"
Margin="152,0,0,0"
Style="{StaticResource BasicTextStyle}"
FontSize="20" />
</Grid>
<Grid
Height="Auto">
<TextBlock
Text="Textblock: "
Margin="5,0,0,0"
Style="{StaticResource BasicTextStyle}"
MaxHeight="60"
FontSize="20" />
<TextBlock
Text="{Binding Name}"
Margin="152,0,0,0"
Style="{StaticResource BasicTextStyle}"
FontSize="20" />
</Grid>
</StackPanel>
</ScrollViewer>
</Border>
</Grid>
</ScrollViewer>
</Grid>
我尝试的下一种方法将事物简化为更合乎逻辑的网格,但是仍然无法使其正常工作。想象一下TextBlock
s 有 30 行。在这里,当运行时,ScrollBar
显示,但没有做任何事情,即使文本明显离开边框区域的底部并且您看不到边框区域的底部。
现在这是直接来自我的代码的示例代码,从页面顶部到相关网格的底部:
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}" />
<TextBlock x:Name="pageTitle" Grid.Column="1" Text="text" Style="{StaticResource PageHeaderTextStyle}" />
</Grid>
<Grid x:Name="PersonViewContent" Grid.Row="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Grid.Row="0" Grid.Column="0" BorderBrush="Black" BorderThickness="5" Width="500" Margin="10,10,10,10">
<ScrollViewer>
<StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="270" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.ColumnSpan="2" Margin="10,10,10,10" VerticalAlignment="Bottom">
<Image Source="text" AutomationProperties.Name="text" ScrollViewer.VerticalScrollBarVisibility="Disabled" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="text"/>
<TextBlock Text="text" Margin="0,180,0,0" TextWrapping="Wrap" Style="{StaticResource SubheaderTextStyle}" MaxHeight="60" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Text="text" Margin="0,215,0,0" TextWrapping="Wrap" Style="{StaticResource SubheaderTextStyle}" MaxHeight="60" FontSize="12" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<TextBlock Grid.Row="1" Grid.ColumnSpan="2" Text="text" Margin="5,0,18,10" TextWrapping="Wrap" Style="{StaticResource SubheaderTextStyle}" MaxHeight="60" FontSize="30"/>
<TextBlock Grid.Row="2" Grid.ColumnSpan="2" Text="text" Margin="5,10,0,0" Style="{StaticResource ViewPersonTextDataHeaderStyle}"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="3" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="4" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="4" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="5" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="5" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="6" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="6" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="7" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="7" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="8" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="8" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="9" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="9" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="10" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="10" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="11" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="11" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="12" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="12" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="13" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="13" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="14" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="14" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="15" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="15" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="16" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="16" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="17" Grid.ColumnSpan="2" Text="text" Margin="5,20,0,0" Style="{StaticResource ViewPersonTextDataHeaderStyle}"/>
<TextBlock Grid.Row="18" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="18" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="19" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="19" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="20" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="20" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="21" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="21" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="22" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="22" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="23" Grid.ColumnSpan="2" Text="text" Margin="5,20,0,0" Style="{StaticResource ViewPersonTextDataHeaderStyle}"/>
<TextBlock Grid.Row="24" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="24" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="25" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="25" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="26" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="26" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="27" Grid.Column="0" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="27" Grid.Column="1" Text="text" Margin="5,0,0,0" Style="{StaticResource ViewPersonTextDataStyle}"/>
<TextBlock Grid.Row="28" Grid.ColumnSpan="2" Text="text" Margin="5,20,0,0" Style="{StaticResource ViewPersonTextDataHeaderStyle}"/>
<TextBlock Grid.Row="29" Grid.ColumnSpan="2" Text="text" Margin="5,0,0,0" Style="{StaticResource BasicTextStyle}" IsTapEnabled="False" IsRightTapEnabled="False" IsHoldingEnabled="False" IsDoubleTapEnabled="False" FontSize="16"/>
</Grid>
</StackPanel>
</ScrollViewer>
</Border>
无论如何,在这上面旋转我的轮子......希望有一个建议
编辑:这是我想要实现的布局的大致草图:
|=========================================
|back button and title area |
| |
| |===============| |
| | | Grid View here for |
| | Picture area | other stuff that the |
| | | User can click on |
| | Start of text | |
| | data of all | |
| | textblocks | |
| | 30+ rows | |
| | textblock | |
| | textblock | |
| | textblock | |
| | textblock | |
| | textblock | |
| | textblock | |
| | textblock | |
| | textblock | |
| |===============| |
|========================================|