Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF. Is it possible to do ellipse "rectangle bounds" hittest?

Tags:

c#

wpf

hittest

Is there possible to make hit test in ellipse bound rectangle, like on this image?

enter image description here

like image 468
slavka Avatar asked Sep 26 '16 13:09

slavka


1 Answers

you can put them both into a border grid and check if it was clicked

XAML:

            <Grid MouseDown="Border_MouseDown">
                <Rectangle Width="100"
                           Height="100"
                           Fill="Green" />
                <Ellipse Width="100"
                         Height="100"
                         Fill="Orange" />
            </Grid>

Code behind

   private void Border_MouseDown(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("hit it");
        }

EDIT Just to make it complete here comes the XAML for green regions only:

   <Grid>
            <Rectangle Width="100"
                       Height="100"
                       Fill="Green"
                       MouseDown="Border_MouseDown" />
            <Ellipse Width="100"
                     Height="100"
                     Fill="Orange" />
        </Grid>
like image 122
Mat Avatar answered Sep 27 '22 01:09

Mat