0

这里有一个奇怪的问题。我已经根据标准模板为 ListBox 创建了一个模板(即,除了我在下面指出的内容之外,我没有更改任何内容)。

我正在尝试在模板的侧面添加几个按钮,以便我可以左右滚动 ScrollViewer(它是标准 ListBox 模板的一部分)。问题是它只能识别 ScrollBar.PageLeftCommand 或 ScrollBar.PageRightCommand ...我无法让它同时响应这两者。

换句话说,如果我单击右键,它将向右翻页,但如果我单击左键,它不会执行任何操作。根据 XAML 中 Button 的顺序,它将指示哪个命令有效,哪个无效(该命令似乎适用于 XAML 中定义的最后一个按钮)。

<ControlTemplate TargetType="{x:Type s:SurfaceListBox}">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.137*"/>
            <ColumnDefinition Width="0.726*"/>
            <ColumnDefinition Width="0.137*"/>
        </Grid.ColumnDefinitions>
        <Border x:Name="Border"  Grid.ColumnSpan="1" Grid.Column="1">
            <s:SurfaceScrollViewer x:Name="scrollViewer" >
                <ItemsPresenter />
            </s:SurfaceScrollViewer>
        </Border>
        <s:SurfaceButton x:Name="rightScroll" Content="&gt;" Command="ScrollBar.PageRightCommand" CommandTarget="{Binding ElementName=scrollViewer}" Grid.Column="2" />
        <s:SurfaceButton x:Name="leftScroll" Content="&lt;" Command="ScrollBar.PageLeftCommand" CommandTarget="{Binding ElementName=scrollViewer}"/>
    </Grid>
</ControlTemplate>

(是的,这是使用 Surface 类,但我已经用普通类尝试过,我得到了相同的行为..)

我看过它与 Snoop 一起运行,但它告诉我这些命令没有任何用处 - 根据 Snoop,这两个命令都已成功处理!

4

2 回答 2

2

The standard WPF controls do not support all of the events with the SurfaceScrollViewer, however, there are other controls packaged with the SurfaceScrollViewer that support some events, like Click.

The problem is that the SurfaceScrollViewer not only accepts touch input on the scrollbar, but also on the content itself.

于 2011-03-20T01:13:32.377 回答
0

好吧,我撒谎了。我没有尝试用SurfaceScrollViewer普通的ScrollViewer.

When I do that it appears to work. So unless anyone has any other suggestions it appears that the SurfaceScrollViewer has at least two bugs (the second being I found is the ScrollBar do not respond to commands when they are hidden unlike the regular ScrollViewer).

Foiled again.

:-(

于 2010-09-09T00:38:50.257 回答