wpf 滚动查看器问题

发布于 2024-09-08 04:07:05 字数 1697 浏览 5 评论 0原文

我正在列表框中显示图像。我已将此列表框放置在滚动查看器中。我使用两个重复按钮来移动列表框项目。我使用 datacontext 绑定列表框。

问题:

如果我使用按钮移动图像并单击列表框中的图像,它将移动到初始位置。

代码:

   <RepeatButton Click="rbtnLeft_Click" Name="rbtnLeft" Width="30" Height="30">
                <Image Source="Images/GeneralImages/search_right_arrow.jpg"></Image>
            </RepeatButton>
            <Grid  x:Name="grid"  Width="666" HorizontalAlignment="Left">
                <ScrollViewer Grid.Row="1" Name="svGame"
                VerticalScrollBarVisibility="Hidden" 
                HorizontalScrollBarVisibility="Hidden"  >
                    <ListBox ClipToBounds="True" Name="lbGameImage" Width="Auto" SelectionChanged="lbGameImage_SelectionChanged" ItemsSource="{Binding}"   ItemsPanel="{DynamicResource iptListBox}" ItemContainerStyle="{DynamicResource ListBoxItemStyle}"
              ScrollViewer.VerticalScrollBarVisibility="Hidden" 
              ScrollViewer.HorizontalScrollBarVisibility="Hidden"/>
                </ScrollViewer>                                       
            </Grid>
            <RepeatButton Click="rbtnRight_Click" Name="rbtnRight" Width="30" Height="30">
                <Image Source="Images/GeneralImages/search_left_arrow.jpg"></Image>
            </RepeatButton>

c# 代码:

private void rbtnLeft_Click(object sender, RoutedEventArgs e)
    {
        svGame.ScrollToHorizontalOffset(svGame.HorizontalOffset + 5);
    }

    private void rbtnRight_Click(object sender, RoutedEventArgs e)
    {
        svGame.ScrollToHorizontalOffset(svGame.HorizontalOffset - 5);
    }

I am displaying images inside the listbox. i have placed this listbox inside the scrollviewer. I am using two repeat button to move the listbox items. I am binding the listbox using datacontext.

Problem:

If i move the images using the button and click on the image in the lisbox it moves to the initial position.

Code:

   <RepeatButton Click="rbtnLeft_Click" Name="rbtnLeft" Width="30" Height="30">
                <Image Source="Images/GeneralImages/search_right_arrow.jpg"></Image>
            </RepeatButton>
            <Grid  x:Name="grid"  Width="666" HorizontalAlignment="Left">
                <ScrollViewer Grid.Row="1" Name="svGame"
                VerticalScrollBarVisibility="Hidden" 
                HorizontalScrollBarVisibility="Hidden"  >
                    <ListBox ClipToBounds="True" Name="lbGameImage" Width="Auto" SelectionChanged="lbGameImage_SelectionChanged" ItemsSource="{Binding}"   ItemsPanel="{DynamicResource iptListBox}" ItemContainerStyle="{DynamicResource ListBoxItemStyle}"
              ScrollViewer.VerticalScrollBarVisibility="Hidden" 
              ScrollViewer.HorizontalScrollBarVisibility="Hidden"/>
                </ScrollViewer>                                       
            </Grid>
            <RepeatButton Click="rbtnRight_Click" Name="rbtnRight" Width="30" Height="30">
                <Image Source="Images/GeneralImages/search_left_arrow.jpg"></Image>
            </RepeatButton>

c# Code:

private void rbtnLeft_Click(object sender, RoutedEventArgs e)
    {
        svGame.ScrollToHorizontalOffset(svGame.HorizontalOffset + 5);
    }

    private void rbtnRight_Click(object sender, RoutedEventArgs e)
    {
        svGame.ScrollToHorizontalOffset(svGame.HorizontalOffset - 5);
    }

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

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

发布评论

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

评论(2

注定孤独终老 2024-09-15 04:07:05

问题是 ListBox 认为它拥有 ScrollViewer,因此每当选择更改时,它都会将偏移量设置回它想要的值。在 ListBox 中设置 ScrollViewer.CanContentScroll="False" 以防止出现这种情况。

The problem is that the ListBox thinks it owns the ScrollViewer, so whenever the selection changes it sets the offset back to what it wants. Set ScrollViewer.CanContentScroll="False" in the ListBox to prevent this.

南街九尾狐 2024-09-15 04:07:05

您需要关闭 ListBox 内的内部 ScrollViewer。您可以通过重新模板化 lbGameImage 以完全删除 ScrollViewer 来完成此操作,但更快的方法(看起来您尝试这样做)是将 lbGameImage 上的两个 ScrollBarVisibility 设置设置为“禁用”。隐藏意味着它们仍然处于活动状态并滚动内容,您只是看不到它们。

You need to turn off the internal ScrollViewer inside the ListBox. You could do it by re-templating lbGameImage to remove the ScrollViewer completely but the quicker way (which it looks like you tried to do) is to set both of the ScrollBarVisibility settings on lbGameImage to "Disabled". Hidden means that they're still active and scrolling the content, you just can't see them.

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