Recommended

Skip Navigation LinksHome / Tips / Controls and UI

Controls and UI

+
Page 
Items Resolution

  • 2 comments  /  posted by  Denislav Savkov  on  Aug 29, 2008 (more than a year ago)

    If you have used multiple threads or just timers in your applications, you probably know that if you have to update any user interface, control you should not do it from any other thread but from the one that the control was created from. That is why if your application uses multiple threads, you always have to be aware of what thread you are in.
    In Silverlight invoking a piece of code in the user interface thread can be achieved by using the BeginInvoke method of the System.Windows.Threading.Dispatcher class.

    Share


  • 0 comments  /  posted by  Denislav Savkov  on  Aug 29, 2008 (more than a year ago)

    In some scenarios we need to find out what are the objects located at a specific point or in a certain area. In this case we get access to the System.Windows.UIElelement objects using the UIElement.HitTest method. It can test a Rect area or a Point. The return value is a collection of the children in this area arranged from the top element to the bottom.

    C#

    Rect areaInAbsoluteCoordinates = new Rect( areaLeftCoordinate, areaTopCoordinate, areaWidth, areaHeight );
    IEnumerable<UIElement> childrenInArea = panel.HitTest(areaInAbsoluteCoordinates );

    Note! In Silverlight the coordinates for hit testing are the absolute coordinates of the application.

    Share
  • 0 comments  /  posted by  Denislav Savkov  on  Aug 29, 2008 (more than a year ago)

    In Silverlight for hit testing are used the absolute coordinates of the application. In case you want to hit test with coordinates relative to a System.Windows.UIElement you need to get the coordinates of the UIElement relative to the application root (i.e. the absolute coordinates of an element ).

    C#

    GeneralTransform generalTransform = uiElement.TransformToVisual( Application.Current.RootVisual);
    Point elementToApplicationRootCoords = generalTransform.Transform( new Point( 0, 0 ) );

    And then add them to the coordinates relative to the element.

    Share
  • 2 comments  /  posted by  Denislav Savkov  on  Aug 29, 2008 (more than a year ago)

    You can get the coordinates of a System.Windows.UIElement relative to any other UIElement. Probably the most common scenario is to get the coordinates of a child element so this is our example.

    C#

    GeneralTransform generalTransform = childElement.TransformToVisual( parentElement );
    Point childToParentCoordinates = generalTransform.Transform( new Point( 0, 0 ) );

    Note! If the child is in left of the parent element or above it, the coordinates will be negative.

    Share
  • 0 comments  /  posted by  Denislav Savkov  on  Aug 29, 2008 (more than a year ago)

    System.Windows.Application is a special class dedicated to the application. Using it you can get a few useful references one of which is the RootVisual.

    C#

    UIElement applicationRoot = Application.Current.RootVisual;

    That's it!

    Share

Page 
Help us make SilverlightShow even better and win a free t-shirt. Whether you'd like to suggest a change in the structure, content organization, section layout or any other aspect of SilverlightShow appearance - we'd love to hear from you! Need a material (article, tutorial, or other) on a specific topic? Let us know and SilverlightShow content authors will work to have that prepared for you. (hide this)