2009-07-01 144 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。