Scrollviewer 没有高度不滚动
Scrollviewer not scrolling without height
我正在编写 Windows Phone 8.1 应用程序 (WINRT)。
我在页面中实现了 scrollviewer。它包含一个 stackpanel 具有 richtextblock 和长文本 ,以及一个 button.
但问题是这个滚动查看器根本不滚动。如果我手动设置 height 给这个 scrollviewer 它正在滚动,但它在更高的分辨率下看起来很难看。如何在没有手动高度的情况下使这个滚动查看器工作。
<ScrollViewer Name="WhyJoin_User_Content_Scroll"
Margin="0,10,0,10"
VerticalScrollBarVisibility="Auto"
>
<StackPanel Orientation="Vertical">
<RichTextBlock Name="WhyJoin_User_Content_RichTextBlock"
FontWeight="Light"
Margin="20,10,20,0"
Foreground="{StaticResource DefaultTheme_DarkBlueColor}"
FontSize="19"
TextWrapping="Wrap"
TextAlignment="Justify">
<RichTextBlock.Blocks>
<Paragraph>
<Paragraph.Inlines>
<Run Text=" Text Text Text Text Text Text Text Text ">
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text=" Text Text Text Text Text Text Text Text ">
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text=" Text Text Text Text Text Text Text Text "></Run>
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text=" Text Text Text Text Text Text Text Text "></Run>
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text="i: Practice work hours of experts"></Run>
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text="ii: Address, Phone numbers etc."></Run>
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text="iii: Appointment requests"></Run>
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text=" Text Text Text Text Text Text Text Text "></Run>
</Paragraph.Inlines>
</Paragraph>
</RichTextBlock.Blocks>
</RichTextBlock>
<Button
x:Name="ButtonWhyJoin_User_Register"
BorderThickness="0"
Width="150"
Height="70"
Margin="0,10,0,0"
HorizontalAlignment="Center"
Click="ButtonWhyJoin_User_Register_Click"
FontWeight="ExtraLight"
Background="{StaticResource DefaultTheme_DarkBlueColor}"
BorderBrush="{x:Null}"
Style="{StaticResource ButtonStyleYesNo}"
Foreground="{StaticResource DefaultTheme_BackgroundColor}"/>
</StackPanel>
</ScrollViewer>
解决您问题的最简单方法是将滚动查看器的高度 and/or 宽度绑定到 ContentRoot。这在 Blend 中最容易完成,通过执行此操作,无论屏幕分辨率如何,您都会自动达到所需的高度。
这就是 XAML 的样子
<ScrollViewer HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" Width="175" Height="{Binding ActualHeight, ElementName=ContentRoot}"/>
我正在编写 Windows Phone 8.1 应用程序 (WINRT)。
我在页面中实现了 scrollviewer。它包含一个 stackpanel 具有 richtextblock 和长文本 ,以及一个 button.
但问题是这个滚动查看器根本不滚动。如果我手动设置 height 给这个 scrollviewer 它正在滚动,但它在更高的分辨率下看起来很难看。如何在没有手动高度的情况下使这个滚动查看器工作。
<ScrollViewer Name="WhyJoin_User_Content_Scroll"
Margin="0,10,0,10"
VerticalScrollBarVisibility="Auto"
>
<StackPanel Orientation="Vertical">
<RichTextBlock Name="WhyJoin_User_Content_RichTextBlock"
FontWeight="Light"
Margin="20,10,20,0"
Foreground="{StaticResource DefaultTheme_DarkBlueColor}"
FontSize="19"
TextWrapping="Wrap"
TextAlignment="Justify">
<RichTextBlock.Blocks>
<Paragraph>
<Paragraph.Inlines>
<Run Text=" Text Text Text Text Text Text Text Text ">
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text=" Text Text Text Text Text Text Text Text ">
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text=" Text Text Text Text Text Text Text Text "></Run>
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text=" Text Text Text Text Text Text Text Text "></Run>
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text="i: Practice work hours of experts"></Run>
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text="ii: Address, Phone numbers etc."></Run>
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text="iii: Appointment requests"></Run>
</Paragraph.Inlines>
</Paragraph>
<Paragraph>
<Paragraph.Inlines>
<Run Text=" Text Text Text Text Text Text Text Text "></Run>
</Paragraph.Inlines>
</Paragraph>
</RichTextBlock.Blocks>
</RichTextBlock>
<Button
x:Name="ButtonWhyJoin_User_Register"
BorderThickness="0"
Width="150"
Height="70"
Margin="0,10,0,0"
HorizontalAlignment="Center"
Click="ButtonWhyJoin_User_Register_Click"
FontWeight="ExtraLight"
Background="{StaticResource DefaultTheme_DarkBlueColor}"
BorderBrush="{x:Null}"
Style="{StaticResource ButtonStyleYesNo}"
Foreground="{StaticResource DefaultTheme_BackgroundColor}"/>
</StackPanel>
</ScrollViewer>
解决您问题的最简单方法是将滚动查看器的高度 and/or 宽度绑定到 ContentRoot。这在 Blend 中最容易完成,通过执行此操作,无论屏幕分辨率如何,您都会自动达到所需的高度。
这就是 XAML 的样子
<ScrollViewer HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" Width="175" Height="{Binding ActualHeight, ElementName=ContentRoot}"/>