private void LoadTemplateFromResource(int count, bool enableRotation)
{
if (string.IsNullOrEmpty(entireStyle))
{
outGridStyle = StyleUtility.XamlFileToString("/SuperMap.WindowsPhone;component/Clustering/OutGridStyle.xaml");
if (enableRotation)
{
entireStyle = StyleUtility.XamlFileToString("/SuperMap.WindowsPhone;component/Clustering/Scatter/ScatterStyle.xaml");
}
else
{
entireStyle = StyleUtility.XamlFileToString("/SuperMap.WindowsPhone;component/Clustering/Scatter/ScatterStyleWithoutRotation.xaml");
}
}
StringBuilder outGrids = new StringBuilder();
StringBuilder clusterIDs = new StringBuilder();
double angle = 0.0;
double deltaAngle = 360.0 / count;
for (int i = 0; i < count; i++)
{
string id = ClusterUtil.BuildClusterIDs(clusterIDs, i);
ClusterUtil.BuildOutGrids(outGridStyle, "0", angle, id, outGrids);
angle += deltaAngle;
}
//连续替换两次,构造出复杂的xaml
string xaml = entireStyle.Replace("{OutGrids}", outGrids.ToString()).Replace("{IDs}", clusterIDs.ToString());
base.ControlTemplate = XamlReader.Load(xaml) as ControlTemplate;
}
}