我正在创建一种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>
和
public partial class ScrollWheel : UserControl
{
private bool _isDial1 = true;
public ScrollWheel()
{
InitializeComponent();
}
private ICommand _scrollTheWheel;
public ICommand ScrollTheWheel
{
get
{
if(_scrollTheWheel == null)
{
_scrollTheWheel = new DelegateCommand(_ => SwitchImage(), _ => true);
}
return _scrollTheWheel;
}
}
private void SwitchImage()
{
if(_isDial1)
{
(Background as ImageBrush).ImageSource = new BitmapImage(new Uri("dial2.png"));
_isDial1 = false;
}
else
{
(Background as ImageBrush).ImageSource = new BitmapImage(new Uri("dial1.png"));
_isDial1 = true;
}
}
}
然而,转动轮子并没有改变背景图像。我怎样才能改变图像?