ScrollViewer - 滚动不适用于 ScrollViewer 内的图像

发布于 2024-12-11 13:49:27 字数 3901 浏览 0 评论 0原文

我有一个ScrollViewer,里面有一些内容。问题是滚动无法正常工作。当您用手指滚动内容然后松开时,可滚动区域始终会弹回到顶部。它只是像弹性一样弹起,不会停留在您滚动到的底部。

<Grid Name="DetailPane" Margin="0,0,0,65" VerticalAlignment="Bottom" Visibility="Collapsed" Background="White" Opacity="0.85">
    <StackPanel>
        <Grid VerticalAlignment="Top">
            <Button Margin="0" Padding="0" Click="CloseDetailPanel" HorizontalAlignment="Right" >
                <Button.Content>
                    <Image Source="images\appbar.close.rest.small.png" Width="20" Height="20"></Image>
                </Button.Content>
            </Button>
        </Grid>
        <ScrollViewer x:Name="contentScrollViewer" VerticalAlignment="Top">
            <Grid>
                <StackPanel>
                    <TextBlock Padding="10,0,10,0" HorizontalAlignment="Left" Name="titleTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" FontWeight="Bold" />
                    <Image x:Name="contentThumbnail" Source="bild.jpg" Visibility="Visible" Width="400" Height="300" Margin="10" />
                    <TextBlock Padding="10" HorizontalAlignment="Left" Name="statusTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" />
                    <HyperlinkButton Padding="0,5,0,10" x:Name="WikipeadiaLink" HorizontalAlignment="Left" VerticalAlignment="Bottom" Content="More on Wikipedia" TargetName="_blank"  NavigateUri="" Foreground="Blue" FontSize="18" />
                </StackPanel>
            </Grid>
        </ScrollViewer>
    </StackPanel>
</Grid>

实际上,我以前也遇到过类似的问题,我在 Stack Overflow 的帮助下设法解决了这个问题……然而,我再次在这里寻求有关同一主题的帮助…… 谢谢你!

更新: 根据建议,我删除了 StackPanels 并将其替换为 Grids。格式完美,但我仍然遇到同样的滚动问题!内容还是回到开头!

<Grid Name="DetailPane" Margin="0,0,0,65" VerticalAlignment="Bottom" Visibility="Collapsed" Background="White" Opacity="0.85">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0" VerticalAlignment="Top">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Button Grid.Row="0"  Margin="0" Padding="0" Click="CloseDetailPanel" HorizontalAlignment="Right" >
            <Button.Content>
                <Image Source="images\appbar.close.rest.small.png" Width="20" Height="20"></Image>
            </Button.Content>
        </Button>
    </Grid>
    <Grid Grid.Row="1">
        <ScrollViewer x:Name="contentScrollViewer" VerticalAlignment="Top">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" Padding="10,0,10,0" HorizontalAlignment="Left" Name="titleTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" FontWeight="Bold" />
                <Image x:Name="contentThumbnail" Grid.Row="1" Source="bild.jpg" Visibility="Visible" Width="400" Height="300" Margin="10" />
                <TextBlock Grid.Row="2"  Padding="10" HorizontalAlignment="Left" Name="statusTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" />
                <HyperlinkButton Grid.Row="3" Padding="0,5,0,10" x:Name="WikipeadiaLink" HorizontalAlignment="Left" VerticalAlignment="Bottom" Content="More on Wikipedia" TargetName="_blank"  NavigateUri="" Foreground="Blue" FontSize="18" />
            </Grid>
        </ScrollViewer> 
    </Grid>
</Grid>

I have a ScrollViewer, inside of which is some content. The problem is that the scroll doesn't work properly. When you scroll the content with your finger and then release, the scrollable area always snaps back to the top. It just bounces like elastic, and won't stay at the bottom where you scrolled it to.

<Grid Name="DetailPane" Margin="0,0,0,65" VerticalAlignment="Bottom" Visibility="Collapsed" Background="White" Opacity="0.85">
    <StackPanel>
        <Grid VerticalAlignment="Top">
            <Button Margin="0" Padding="0" Click="CloseDetailPanel" HorizontalAlignment="Right" >
                <Button.Content>
                    <Image Source="images\appbar.close.rest.small.png" Width="20" Height="20"></Image>
                </Button.Content>
            </Button>
        </Grid>
        <ScrollViewer x:Name="contentScrollViewer" VerticalAlignment="Top">
            <Grid>
                <StackPanel>
                    <TextBlock Padding="10,0,10,0" HorizontalAlignment="Left" Name="titleTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" FontWeight="Bold" />
                    <Image x:Name="contentThumbnail" Source="bild.jpg" Visibility="Visible" Width="400" Height="300" Margin="10" />
                    <TextBlock Padding="10" HorizontalAlignment="Left" Name="statusTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" />
                    <HyperlinkButton Padding="0,5,0,10" x:Name="WikipeadiaLink" HorizontalAlignment="Left" VerticalAlignment="Bottom" Content="More on Wikipedia" TargetName="_blank"  NavigateUri="" Foreground="Blue" FontSize="18" />
                </StackPanel>
            </Grid>
        </ScrollViewer>
    </StackPanel>
</Grid>

I've actually had a similar problem before, which I managed to solve with help from Stack Overflow... and yet, here I am again, asking for help on the same topic...
thanks heaps!

UPDATE:
Based on suggestions, I removed the StackPanels and replaced them with Grids. The formatting is perfect, but I still have the same scroll problem! The content still snaps back to the beginning!

<Grid Name="DetailPane" Margin="0,0,0,65" VerticalAlignment="Bottom" Visibility="Collapsed" Background="White" Opacity="0.85">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0" VerticalAlignment="Top">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Button Grid.Row="0"  Margin="0" Padding="0" Click="CloseDetailPanel" HorizontalAlignment="Right" >
            <Button.Content>
                <Image Source="images\appbar.close.rest.small.png" Width="20" Height="20"></Image>
            </Button.Content>
        </Button>
    </Grid>
    <Grid Grid.Row="1">
        <ScrollViewer x:Name="contentScrollViewer" VerticalAlignment="Top">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" Padding="10,0,10,0" HorizontalAlignment="Left" Name="titleTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" FontWeight="Bold" />
                <Image x:Name="contentThumbnail" Grid.Row="1" Source="bild.jpg" Visibility="Visible" Width="400" Height="300" Margin="10" />
                <TextBlock Grid.Row="2"  Padding="10" HorizontalAlignment="Left" Name="statusTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" />
                <HyperlinkButton Grid.Row="3" Padding="0,5,0,10" x:Name="WikipeadiaLink" HorizontalAlignment="Left" VerticalAlignment="Bottom" Content="More on Wikipedia" TargetName="_blank"  NavigateUri="" Foreground="Blue" FontSize="18" />
            </Grid>
        </ScrollViewer> 
    </Grid>
</Grid>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

俯瞰星空 2024-12-18 13:49:27

这是因为 stackPanel,请尝试将其替换为 Grid 等其他内容。

试试这个,我删除了多余的网格并为滚动查看器添加了拉伸对齐:

<Grid Name="DetailPane" Margin="0,0,0,65" VerticalAlignment="Bottom" Visibility="Collapsed" Background="White" Opacity="0.85">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Button Grid.Row="0"  Click="CloseDetailPanel" HorizontalAlignment="Right" VerticalAlignment="Top">
        <Button.Content>
            <Image Source="images\appbar.close.rest.small.png" Width="20" Height="20"></Image>
        </Button.Content>
    </Button>


        <ScrollViewer x:Name="contentScrollViewer" VerticalAlignment="Stretch" Grid.Row="1"HorizontalAlignment="Stretch">
            <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" Padding="10,0,10,0" HorizontalAlignment="Left" Name="titleTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" FontWeight="Bold" />
                <Image x:Name="contentThumbnail" Grid.Row="1" Source="bild.jpg" Visibility="Visible" Width="400" Height="300" Margin="10" />
                <TextBlock Grid.Row="2"  Padding="10" HorizontalAlignment="Left" Name="statusTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" />
                <HyperlinkButton Grid.Row="3" Padding="0,5,0,10" x:Name="WikipeadiaLink" HorizontalAlignment="Left" VerticalAlignment="Bottom" Content="More on Wikipedia" TargetName="_blank"  NavigateUri="" Foreground="Blue" FontSize="18" />
            </Grid>
        </ScrollViewer>

</Grid>

Its because of the stackPanel, try replacing it with something else like Grid.

Try this, I removed a redundant grid and added stretched alignment for the scroll viewer:

<Grid Name="DetailPane" Margin="0,0,0,65" VerticalAlignment="Bottom" Visibility="Collapsed" Background="White" Opacity="0.85">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Button Grid.Row="0"  Click="CloseDetailPanel" HorizontalAlignment="Right" VerticalAlignment="Top">
        <Button.Content>
            <Image Source="images\appbar.close.rest.small.png" Width="20" Height="20"></Image>
        </Button.Content>
    </Button>


        <ScrollViewer x:Name="contentScrollViewer" VerticalAlignment="Stretch" Grid.Row="1"HorizontalAlignment="Stretch">
            <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" Padding="10,0,10,0" HorizontalAlignment="Left" Name="titleTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" FontWeight="Bold" />
                <Image x:Name="contentThumbnail" Grid.Row="1" Source="bild.jpg" Visibility="Visible" Width="400" Height="300" Margin="10" />
                <TextBlock Grid.Row="2"  Padding="10" HorizontalAlignment="Left" Name="statusTextBlock" TextWrapping="Wrap" Foreground="#FF2B2929" />
                <HyperlinkButton Grid.Row="3" Padding="0,5,0,10" x:Name="WikipeadiaLink" HorizontalAlignment="Left" VerticalAlignment="Bottom" Content="More on Wikipedia" TargetName="_blank"  NavigateUri="" Foreground="Blue" FontSize="18" />
            </Grid>
        </ScrollViewer>

</Grid>
醉梦枕江山 2024-12-18 13:49:27

最终解决这个问题的方法是向 ScrollViewer 添加静态高度。我意识到没有人能看到这一点,因为我省略了显示这是在 PivotItem 内部的代码部分。

根据此讨论: http://forums.create.msdn.com/forums/ t/84933.aspx 当 ScrollViewer 在 Pivot 内部时,它会停止正常工作,除非它定义了静态高度。

真气人!

What solved this, in the end, was adding a static height to the ScrollViewer. I realise noone could have seen this as I omitted the part of the code that shows that this is inside a PivotItem.

According to this discussion: http://forums.create.msdn.com/forums/t/84933.aspx a ScrollViewer stops working properly when it is inside a Pivot, unless it has a static height defined.

Infuriating!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文