开发者

Why is one of my ScrollViewer commands not working in ListBox template?

Got a weird problem here. I have created a template for a ListBox based on the standard template (i.e. I have not changed anything other than what I indicate below).

I am trying to add a couple of buttons to the side of the template so that I can scroll the ScrollViewer (which is part of the standard ListBox template) left and right. The problem is that it only recognises the ScrollBar.PageLeftCommand OR the ScrollBar.PageRightCommand ... I cannot get it to response to both.

In other words if I click the right button it will page right, but if I click the left button it doesn't do anything. Depending on the ordering of the Button in the XAML that will dictate which command works and which doesn't (it appears the command works for the last button defined in the 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>

(Yes this is using the Surface classes but I have tried it with normal ones and I get the same behaviour..)

I have had a look at it running with Snoop but it tells me nothing useful about the commands - according to Snoop both the commands are handled successfully!


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.


Ok, I lied. I did not try replacing the SurfaceScrollViewer with a normal 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.

:-(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜