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

浪子不回头ぞ 提交于 2019-12-10 14:34:47

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/39703613/wpf-is-it-possible-to-do-ellipse-rectangle-bounds-hittest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!