This question is locked. New answers and comments are not allowed.
Hey guys,
Currently I'm creating my map polygons programatically but want to move it over to xaml and I'm having a problem getting the polygons to show from my xaml.
This is how I was doing it previously and it works fine:
Currently I'm creating my map polygons programatically but want to move it over to xaml and I'm having a problem getting the polygons to show from my xaml.
This is how I was doing it previously and it works fine:
MapPolygon polygon =
new
MapPolygon()
{
Points = coll,
Fill =
new
SolidColorBrush(fill),
Stroke =
new
SolidColorBrush(stroke),
StrokeThickness = 2,
Tag = p
};
System.Xml.Linq.XElement xTextBlock =
new
System.Xml.Linq.XElement(
"TextBlock"
);
xTextBlock.SetAttributeValue(
"Text"
,
"Name: "
+ p.Name +
"\n"
+ p.Type +
" Name: "
+ p.OwnerName);
DataTemplate template = (DataTemplate)XamlReader.Load(
@"<DataTemplate
xmlns=
""
http:
//schemas.microsoft.com/client/2007"">
" + xTextBlock.ToString(System.Xml.Linq.SaveOptions.DisableFormatting)
+
"</DataTemplate>"
);
polygon.CaptionLocation =
new
Location(p.PointData[0].PointLatitude, p.PointData[0].PointLongitude);
polygon.CaptionTemplate = template;
shapeLayer.Items.Add(polygon);
The new way I'm doing it is like this
<
UserControl
x:Class
=
"WIMMS.UI.Module.Main.Controls.SimplePolygonInfo"
xmlns:local
=
"clr-namespace:WIMMS.UI.Module.Main"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"400"
>
<
Grid
x:Name
=
"LayoutRoot"
>
<
telerik:MapPolygon
x:Name
=
"MapPolygonItem"
Points
=
"{Binding PointData}"
Fill
=
"Red"
Stroke
=
"Red"
StrokeThickness
=
"2"
/>
</
Grid
>
</
UserControl
>
public
partial
class
SimplePolygonInfo : UserControl
{
private
IEventAggregator _events;
private
ICommonService _commonService;
public
SimplePolygonInfo(IEventAggregator events, ICommonService commonService)
{
InitializeComponent();
_events = events;
DataContext =
this
;
_commonService = commonService;
}
public
static
readonly
DependencyProperty pointsProperty =
DependencyProperty.Register(
"PointData"
,
typeof
(LocationCollection),
typeof
(SimplePolygonInfo),
new
PropertyMetadata(
new
LocationCollection()));
public
LocationCollection PointData
{
get
{
return
(LocationCollection)GetValue(pointsProperty);
}
set
{
SetValue(pointsProperty, value);
}
}
}
And the logic changes to this:
SimplePolygonInfo polyInfo = _container.Resolve<SimplePolygonInfo>();
polyInfo.PointData = coll;
shapeLayer.Items.Add(polyInfo);
Is it even possible to do it this way?
If I do something such as add a text block above the map polygon I can see that.
<Grid x:Name=
"LayoutRoot"
>
<TextBlock Text=
"Test Text"
/>
<telerik:MapPolygon x:Name=
"MapPolygonItem"
Points=
"{Binding PointData}"
Fill=
"Red"
Stroke=
"Red"
StrokeThickness=
"2"
/>
</Grid>
But can't see the polygon still.
Thanks for the help