I'm trying to set up my polygons to have a click event on them similar to the demo at http://demos.telerik.com/silverlight/#Map/SalesDashboard
I can get the click event to work, however my element.DataContext is always null.
Here is what I have:
xaml
My xaml.cs:
What am I missing that will allow me to get the DataContext for the section of my map that was clicked? The section in question is GetSenderDataPoint. It is hitting the return element.DataContext but that value is always null.
Thanks,
Tim
I can get the click event to work, however my element.DataContext is always null.
Here is what I have:
xaml
<
UserControl
x:Class
=
"ClosestCenter.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local
=
"clr-namespace:ClosestCenter"
mc:Ignorable
=
"d"
d:DesignWidth
=
"640"
d:DesignHeight
=
"480"
>
<
UserControl.Resources
>
<
local:WktDataViewModel
x:Key
=
"DataContext"
/>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
>
<
telerik:RadMap
x:Name
=
"radMap"
Center
=
"39.36830, -95.27340"
ZoomLevel
=
"5"
MouseClickMode
=
"None"
MapMouseClick
=
"radMap_MouseClick"
>
<
telerik:InformationLayer
x:Name
=
"informationLayer"
MouseLeftButtonDown
=
"elementMouseLeftButtonDown"
>
<
telerik:InformationLayer.Reader
>
<
telerik:SqlGeospatialDataReader
Source
=
"{Binding Source={StaticResource DataContext}, Path=WktDataCollection}"
GeospatialPropertyName
=
"Geometry"
ToolTipFormat
=
"Name"
>
<
telerik:SqlGeospatialDataReader.PointTemplate
>
<
DataTemplate
>
<
Border
Background
=
"Yellow"
BorderThickness
=
"1"
Padding
=
"2,2,2,2"
>
<
telerik:MapLayer.HotSpot
>
<
telerik:HotSpot
X
=
"0.5"
Y
=
"0.5"
ElementName
=
"PART_Image"
/>
</
telerik:MapLayer.HotSpot
>
<
Grid
Name
=
"PART_Panel"
>
<
Path
Fill
=
"{Binding Source={StaticResource DataContext},Path=PointBrush}"
Name
=
"PART_Image"
>
<
Path.Data
>
<
GeometryGroup
>
<
EllipseGeometry
Center
=
"7,7"
RadiusX
=
"4"
RadiusY
=
"4"
/>
<
EllipseGeometry
Center
=
"7,7"
RadiusX
=
"6"
RadiusY
=
"6"
/>
</
GeometryGroup
>
</
Path.Data
>
</
Path
>
</
Grid
>
</
Border
>
</
DataTemplate
>
</
telerik:SqlGeospatialDataReader.PointTemplate
>
</
telerik:SqlGeospatialDataReader
>
</
telerik:InformationLayer.Reader
>
<
telerik:InformationLayer.ShapeFill
>
<
telerik:MapShapeFill
Fill
=
"#7FFFFFFF"
Stroke
=
"#5A636B"
StrokeThickness
=
"3"
/>
</
telerik:InformationLayer.ShapeFill
>
<
telerik:InformationLayer.HighlightFill
>
<
telerik:MapShapeFill
Fill
=
"#B2FFFFFF"
Stroke
=
"#5A636B"
StrokeThickness
=
"3"
/>
</
telerik:InformationLayer.HighlightFill
>
</
telerik:InformationLayer
>
</
telerik:RadMap
>
</
Grid
>
</
UserControl
>
My xaml.cs:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
using
Telerik.Windows.Controls.Map;
using
System.Collections.ObjectModel;
using
System.ComponentModel;
namespace
ClosestCenter
{
public
partial
class
MainPage : UserControl
{
private
WktDataRow lastHighlightedWkt;
private
FrameworkElement clickedElement;
private
WktDataViewModel context;
//private WktDataViewModel context;
/*
private Collection<WktDataRow> _wktDataCollection;
public Collection<WktDataRow> WktDataCollection
{
get
{
return this._wktDataCollection;
}
set
{
this._wktDataCollection = value;
}
}
*/
public
MainPage()
{
InitializeComponent();
this
.radMap.Provider =
new
BingMapProvider(MapMode.Aerial,
true
,
"myKey"
);
context =
this
.DataContext
as
WktDataViewModel;
}
private
void
Map_Loaded(
object
sender, RoutedEventArgs e)
{
}
private
object
GetSenderDataPoint()
{
if
(
this
.clickedElement !=
null
)
{
FrameworkElement element =
this
.clickedElement;
this
.clickedElement =
null
;
return
element.DataContext;
}
return
null
;
}
private
WktDataRow GetDataPointWkt(
object
senderDataPoint)
{
return
(WktDataRow)senderDataPoint;
}
private
void
radMap_MouseClick(
object
sender, MapMouseRoutedEventArgs eventArgs)
{
object
senderDataPoint = GetSenderDataPoint();
if
(senderDataPoint !=
null
)
{
WktDataRow wkt =
this
.GetDataPointWkt(senderDataPoint);
this
.SelectWkt(wkt);
}
}
private
void
SelectWkt(WktDataRow wktDataRow)
{
string
test = wktDataRow.Name;
}
private
void
elementMouseLeftButtonDown(
object
sender, MouseButtonEventArgs e)
{
FrameworkElement element = sender
as
FrameworkElement;
if
(element !=
null
)
{
this
.clickedElement = element;
}
}
}
}
What am I missing that will allow me to get the DataContext for the section of my map that was clicked? The section in question is GetSenderDataPoint. It is hitting the return element.DataContext but that value is always null.
Thanks,
Tim