WPF Rectangle does not have a Click event

M. Dudley picture M. Dudley · Jul 1, 2009 · Viewed 26.8k times · Source

It seems that the WPF Rectangle shape does not have the Click event defined. What am I supposed to use instead?

It does have MouseUp, but it's not quite the same behavior.

Answer

Kent Boogaart picture Kent Boogaart · Jul 1, 2009

If you're not happy with MouseDown and MouseUp, perhaps you could just put the Rectangle in a Button and handle the Button's Click event?

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

It really depends with the behavior you're after. Please elaborate if needs be.