This is a migrated thread and some comments may be shown as answers.

Events from Objects on the Information Layer

3 Answers 75 Views
Map
This is a migrated thread and some comments may be shown as answers.
Ziad
Top achievements
Rank 1
Ziad asked on 13 Jul 2010, 09:41 AM
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?

3 Answers, 1 is accepted

Sort by
0
Accepted
Andrey
Telerik team
answered on 13 Jul 2010, 04:06 PM
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
0
Ziad
Top achievements
Rank 1
answered on 14 Jul 2010, 07:55 AM
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?
0
Accepted
Andrey
Telerik team
answered on 14 Jul 2010, 04:34 PM
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
Tags
Map
Asked by
Ziad
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Ziad
Top achievements
Rank 1
Share this question
or