26

I would like to be able to have a button that is not visible, but able to trigger a click event when clicked.

I'm looking at this page MSDN: System.windows.visibilty and it seems that buttons can have three visibility states. Visible, Hidden and Collapsed. When the button is Hidden or Collapsed, I can't see it (which is good) but I can't click it (which is bad).

Does anyone have a way that I can make clickable invisible element in my XAML file?

Jeffrey Greenham
  • 1,382
  • 5
  • 16
  • 33
  • 2
    Does it really have to be a `Button`? You can receive click events from pretty much any control. – Anon. Feb 03 '11 at 22:34
  • Well now this would be useless. Ever heard of discoverability as a design principle? – Cody Gray - on strike Feb 04 '11 at 06:41
  • 1
    @Anon: That is not the case at all. The click event is almost exclusive to the Button control. – H.B. Feb 04 '11 at 06:54
  • 1
    @CodyGray - If someone is required to have an image 'hot spot', so to speak, then a click event on the image as a whole would be useless. Ideally, they would be individual elements (each with events that can be associated to it) but it isn't always possible. – Laura Ritchey Nov 25 '13 at 21:18

2 Answers2

40

Try setting the Button's Opacity...

<Button Opacity="0" />
Gabe
  • 49,577
  • 28
  • 142
  • 181
  • 3
    As an alternate, use Background="#01000000", setting the background color to an almost-transparent color. – abramlimpin Feb 04 '11 at 04:45
  • 7
    And to get rid of the dotted line focus rectangle set `FocusVisualStyle="{x:Null}"` – Cel May 12 '12 at 15:20
  • 2
    Another little tip. If you add the – Damon8or May 20 '13 at 15:42
  • One more tip. The button won't receive a Click event if its contents have manipulations enabled. But you can use a [StylusSystemGesture](http://stackoverflow.com/a/27272024/603828) event instead. – ulatekh Feb 17 '16 at 23:15
3

Can't you use the Opacity property?

Shoban
  • 22,920
  • 8
  • 63
  • 107