您可以使用带有自定义鼠标手势的输入绑定,这很容易实现:
public class MouseWheelUp : MouseGesture
{
public MouseWheelUp(): base(MouseAction.WheelClick)
{
}
public MouseWheelUp(ModifierKeys modifiers) : base(MouseAction.WheelClick, modifiers)
{
}
public override bool Matches(object targetElement, InputEventArgs inputEventArgs)
{
if (!base.Matches(targetElement, inputEventArgs)) return false;
if (!(inputEventArgs is MouseWheelEventArgs)) return false;
var args = (MouseWheelEventArgs)inputEventArgs;
return args.Delta > 0;
}
}
然后像这样使用它:
<TextBlock>
<TextBlock.InputBindings>
<MouseBinding Command="{Binding Command}">
<MouseBinding.Gesture>
<me:MouseWheelUp />
</MouseBinding.Gesture>
</MouseBinding>
</TextBlock.InputBindings>
ABCEFG
</TextBlock>