Select Shape element by clicking inside RRS feed

  • Question

  • I have added few shape elements to the Canvas. In MouseDown function, i can select the element using InputHitTest Method.

    c# code for rectangle:
    ell = new Ellipse();
    ell.Width = 100;
    ell.Height = 100;
    ell.Stroke = Brushes.Blue;
    ell.StrokeThickness = 2.0;
    Canvas.SetTop(ell, 25);
    Canvas.SetLeft(ell, 25);

    InputHitTest returns the Ellipse element by clicking only on edges, but not when user clicks inside the ellipse. I notice that by filling the element it is possible to select the ellipse, but would like to  do without filling it.

    Is it possible to select/highlight the ellipse element, if user clicks inside the rectangle box?
    Wednesday, October 11, 2006 11:53 PM

All replies

  • Why not use a Fill 'Transparent'? It will be filled but the user won't see it, and you can select the ellipse by clicking anywhere in it
    Thursday, October 12, 2006 8:15 AM
  • Using fill, the overlapped elements become invisible and I wouldn't want that behavior.
    Thursday, October 12, 2006 1:46 PM
  • If you set Fill="Transparent" (or, from code, ell.Fill = Brushes.Transparent;) the Fill will not occlude anything behind it but will be present for hit testing.  Note that this will "cover" the overlapped elements from a hit testing perspective, but it sounds like this is what you want.

    -Adam Smith [MS]


    Thursday, October 12, 2006 4:21 PM
  • Thanks Frances83  & Adam. It's working.
    Friday, October 13, 2006 2:14 AM