【问题标题】:Scrollviewer not scrolling without heightScrollviewer 不滚动没有高度
【发布时间】:2015-01-31 06:20:52
【问题描述】:

我正在编写一个 Windows Phone 8.1 应用程序 (WINRT)。

我在页面中实现了 scrollviewer。它包含一个 stackpanel,其中包含 richtextblock 和长文本,以及一个 按钮

但问题是这个滚动查看器根本不滚动。如果我手动设置 height 到此滚动查看器,它正在滚动,但在更高的分辨率下看起来很难看。如何在没有手动高度的情况下使此滚动查看器工作。

<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>

【问题讨论】:

  • 正如我已经尝试过上面的代码 - 它工作正常 - 如果你复制并添加更多段落,以便文本超出视图,那么可以使用 scrollviewer 滚动它。你想达到什么目的?

标签: c# xaml windows-phone windows-phone-8.1 scrollviewer


【解决方案1】:

解决问题的最简单方法是将滚动查看器的高度和/或宽度绑定到 ContentRoot。这在 Blend 中最容易完成,无论屏幕分辨率如何,您都会自动达到所需的高度。

http://pho.to/8kh1T

这就是 XAML 的样子

<ScrollViewer HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" Width="175" Height="{Binding ActualHeight, ElementName=ContentRoot}"/> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-12
    • 2010-11-20
    • 2015-01-26
    • 2010-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多