Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用鼠标滚轮更改背景图像_C#_Wpf_Mousewheel - Fatal编程技术网

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>