2011-07-01 69 views
0

wpf中有一个命令属性,我试图在图像点击时执行。我基本上正在改变一个滚轮的风格。我下载样品款式here并改变我的风格后,我结束了类似:在鼠标点击图像控制时执行命令wpf

enter image description here

确定,所以让我解释一下。顶部有一个箭头指向图像顶部。我打算摆脱顶部箭头,但我需要它的原因是因为在xaml它有一个命令,当点击它向上滚动。对于向上箭头的代码是:

<RepeatButton 
      Style="{StaticResource ScrollBarButton}" 
      Margin="0,15,0,0" 
      VerticalAlignment="Top" 
      Background="#FFFFFFFF" 
      Grid.Row="0"                   
      Command="{x:Static ScrollBar.LineUpCommand}" <!-- This is the line that enables to scroll upwards when clicked --> 
      theme:ScrollChrome.ScrollGlyph="UpArrow" 
      RenderTransformOrigin="0.5, 0.5"> 
      <RepeatButton.RenderTransform> 
      <ScaleTransform ScaleX="4" ScaleY="2"/> 
      </RepeatButton.RenderTransform>  
</RepeatButton> 

总之我感兴趣的下列财产:

Command="{x:Static ScrollBar.LineUpCommand}" 

这将是很好,如果我能摆脱上箭头和地点,在命令图像,而不是。问题是图像控件没有属性命令。我知道我可以使顶部箭头的alpha值等于0,并使其看起来像只有一个图像,但我很了解这是如何工作,而且我想添加更多的功能,如更改图像外观鼠标输入等。

回答

2

创建一个带有控件模板的按钮,只是有一个图像,并绑定到该按钮的命令 。更多关于这可以在这里找到: Attach ICommand in WPF UserControl

+0

可用eventtocommand正是我只是放在按钮而不是图像。但由于某种原因,当我离开鼠标时,它不起作用。 –

+1

尝试模板RepeatButton,而不是按钮只引发一次事件。 – anivas

0

,或者尝试使用在MVVM光无线工具包