为什么我的 ScrollViewer 命令之一在 ListBox 模板中不起作用?
这里遇到一个奇怪的问题。我已经根据标准模板为列表框创建了一个模板(即,除了下面指出的内容之外,我没有更改任何内容)。
我试图在模板的侧面添加几个按钮,以便我可以左右滚动 ScrollViewer(它是标准 ListBox 模板的一部分)。 问题是它只识别 ScrollBar.PageLeftCommand 或 ScrollBar.PageRightCommand ...我无法让它响应两者。
换句话说,如果我单击右键,它将向右翻页,但是如果我单击左侧按钮,它不会执行任何操作。根据 XAML 中按钮的顺序,将决定哪个命令有效,哪个命令无效(看起来该命令适用于 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=">" Command="ScrollBar.PageRightCommand" CommandTarget="{Binding ElementName=scrollViewer}" Grid.Column="2" />
<s:SurfaceButton x:Name="leftScroll" Content="<" Command="ScrollBar.PageLeftCommand" CommandTarget="{Binding ElementName=scrollViewer}"/>
</Grid>
</ControlTemplate>
(是的,这是使用 Surface 类,但我已经用普通类尝试过,并且得到了相同的行为..)
我已经查看了它与 Snoop 一起运行的情况,但它告诉我有关命令的任何有用信息 - 根据 Snoop 的说法命令处理成功!
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=">" Command="ScrollBar.PageRightCommand" CommandTarget="{Binding ElementName=scrollViewer}" Grid.Column="2" />
<s:SurfaceButton x:Name="leftScroll" Content="<" 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标准 WPF 控件并不支持 SurfaceScrollViewer 的所有事件,但是,与 SurfaceScrollViewer 一起打包的其他控件也支持某些事件,例如 Click。
问题是 SurfaceScrollViewer 不仅接受滚动条上的触摸输入,还接受内容本身的触摸输入。
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.
好吧,我撒谎了。我没有尝试用普通的 ScrollViewer 替换 SurfaceScrollViewer。
当我这样做时,它似乎起作用了。因此,除非有人有任何其他建议,否则
SurfaceScrollViewer
似乎至少有两个错误(我发现的第二个错误是ScrollBar
在隐藏时不响应命令,这与常规的 ScrollViewer)。又被挫败了。
:-(
Ok, I lied. I did not try replacing the
SurfaceScrollViewer
with a normalScrollViewer
.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 theScrollBar
do not respond to commands when they are hidden unlike the regularScrollViewer
).Foiled again.
:-(