C# 如何使用鼠标滚轮更改背景图像
我正在创建一个C# 如何使用鼠标滚轮更改背景图像,c#,wpf,mousewheel,C#,Wpf,Mousewheel,我正在创建一个UserControl,我希望它有一个行为,即当用户在上面旋转鼠标滚轮时,背景图像在两个选项之间交替 到目前为止,我得到的是: <UserControl x:Class="OI.MR.UserControls.DataControls.ScrollWheel" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://s
UserControl
,我希望它有一个行为,即当用户在上面旋转鼠标滚轮时,背景图像在两个选项之间交替
到目前为止,我得到的是:
<UserControl x:Class="OI.MR.UserControls.DataControls.ScrollWheel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="118">
<UserControl.Background>
<ImageBrush ImageSource="dial1.png" TileMode="None" />
</UserControl.Background>
<UserControl.InputBindings>
<MouseBinding MouseAction="WheelClick" Command="{Binding ScrollTheWheel}"/>
</UserControl.InputBindings>
</UserControl>
但是,转动方向盘不会改变背景图像。如何更改图像?您的datacontext确实不正确: 一种可能性:
<UserControl.InputBindings>
<MouseBinding MouseAction="WheelClick"
Command="{Binding Path=ScrollTheWheel, RelativeSource={RelativeSource AncestorType={x:Type view:YourUserControl}}}"/>
</UserControl.InputBindings>
(将类型替换为用户控件的类型)是否尝试单击控制盘?-->这就是您注册的事件:MouseAction=“WheelClick”您的操作是
WheelClick
不滚动。@ChrisF:如果MSDN是错误的,我很想知道我应该使用的正确操作。@MattEllen-我得到纠正。您是否验证了它正在进入SwitchImage
中?看起来您根本没有绑定控件的DataContext
。这意味着后续绑定将无法工作。
<UserControl.InputBindings>
<MouseBinding MouseAction="WheelClick"
Command="{Binding Path=ScrollTheWheel, RelativeSource={RelativeSource AncestorType={x:Type view:YourUserControl}}}"/>
</UserControl.InputBindings>