Events from Objects on the Information Layer

4 posts, 2 answers
  1. Ziad
    Ziad avatar
    13 posts
    Member since:
    Apr 2009

    Posted 13 Jul 2010 Link to this post

    I noticed that certain events like ToolTipOpening and PreviewMouseDown are not being fired from objects (like MapPolygon and Ellipse) in the information layer. Is there a specific reason for this? Is it possible to handle these events in some way?
  2. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 13 Jul 2010 Link to this post

    Hi Ziad,

    The events of the map shape objects such as MapPolygon and MapEllipse are propagated to shape objects which are rendered on information layer. The list of these does not contain all events that supported by the FrameworkElement class. Currently map shapes support the following events:
    - MouseEnter
    - MouseLeave
    - MouseLeftButtonDown
    - MouseLeftButtonUp
    - MouseMove
    - MouseWheel

    If you need to attach other events, then you should get the generated shape from items container and attach the event to it directly. The sample code below gets the shape object using the FindChildByType extension. It attaches the handler to the ToolTipOpening event. The AttachEvents method is called after the information layer is rendered.
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.Map;

    private
    delegate void ReaderDelegate(MapShape shape);

    private
    void radMap_MapMouseClick(object sender, MapMouseRoutedEventArgs eventArgs)
    {
        MapEllipse mapEllipse = new MapEllipse();
        mapEllipse.Fill = new SolidColorBrush(Colors.Brown);
        mapEllipse.Width = 2;
        mapEllipse.Height = 2;
        MapLayer.SetLocation(mapEllipse, eventArgs.Location);
        mapEllipse.ToolTip = "Test tooltip";

        
    this.informationLayer.Items.Add(mapEllipse); 

        
    this.Dispatcher.Invoke(DispatcherPriority.Render, new ReaderDelegate(this.AttachEvents), mapEllipse);
    }

    private
    void AttachEvents(MapShape mapShape)
    {
        var element = this.informationLayer.ItemContainerGenerator.ContainerFromItem(mapShape) as FrameworkElement;
        var shape = element.FindChildByType<Shape>();

        
    shape.ToolTipOpening += this.shape_ToolTipOpening;
    }

    void
    shape_ToolTipOpening(object sender, ToolTipEventArgs e)
    {
    }

    Greetings,
    Andrey Murzov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ziad
    Ziad avatar
    13 posts
    Member since:
    Apr 2009

    Posted 14 Jul 2010 Link to this post

    Thank you for you answer Andrey. However, I do not seem to have the extension method 'FindChildByType' defined on the FrameworkElement class. Is it supposed to be included in the Telerik controls?
  5. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 14 Jul 2010 Link to this post

    Hi Ziad,

    To use this extension method you should add using of the Telerik.Windows.Controls namespace. Also you should reference the Telerik.Windows.Controls.dll.

    All the best,
    Andrey Murzov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top