2009-07-01 197 views

回答

30

如果你不快乐与MouseDownMouseUp,也许你可以只放在一个ButtonRectangle和处理ButtonClick事件?

<Button> 
    <Button.Template> 
     <ControlTemplate> 
      <Rectangle .../> 
     </ControlTemplate> 
    </Button.Template> 
</Button> 

这真的取决于你的行为。请详细说明是否需要。

+0

这可能是我想要的。 – 2009-07-01 12:52:27

18

点击移交添加到一个矩形本身,你可以使用InputBindings属性:

<Rectangle Fill="Blue" Stroke="Black"> 
    <Rectangle.InputBindings> 
     <MouseBinding Gesture="LeftClick" Command="{Binding FooCommand}"/> 
    </Rectangle.InputBindings> 
</Rectangle> 

这将导致在单击矩形时要执行的FooCommand。如果您使用MVVM,方便!

+0

这是.NET 4,还是它也可以在.NET 3.5中工作? – 2011-09-09 13:13:35

+0

它在.NET 3.5中可用:http://msdn.microsoft.com/en-us/library/system.windows.uielement.inputbindings(v=VS.90).aspx – Grokys 2011-09-12 13:49:18

4

我正在查找相关的DoubleClick事件,并且遇到了this suggestion,只是将感兴趣的对象嵌入到ContentControl中。

这里是他们的例子(带有边框,也不支持点击/双击)。

<ContentControl MouseDoubleClick="OnDoubleClick"> 
    <Border Margin="10" BorderBrush="Black" BorderThickness="2"> 
     <Grid Margin="4"> 
      <Rectangle Fill="Red" /> 
      <TextBlock Text="Hello" FontSize="15" /> 
     </Grid> 
    </Border> 
</ContentControl> 
0

长方形有事件Tapped,它工作正常。在为Windows 8.1设计通用应用程序时,会发生新事件。 Tapped,DoubleTaped,RightTapped和Holding。