Yale,
Thanks for your response. I’m using the map control DesktopEdition.dll ver. 3.0.362.0 and MapSuiteCore.dll ver. 3.1.182.0. The ZedGraph.dll version is 5.1.4.31904 and ZedGraphStyleExtension.dll ver. 3.0.362.0.
I tried the HowDoI sample solution for ZedGraph and it works fine in that solution but the same does not work in my test WPF solution. Here’s the code from my test solution:
Window1.xaml code:
<Window x:Class=“MapSuiteTest.Window1”
xmlns=“schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=“schemas.microsoft.com/winfx/2006/xaml”
xmlns:my=“clr-namespace:ThinkGeo.MapSuite.DesktopEdition;assembly=DesktopEdition” Loaded=“Window1_Load”
Title=“Window1” Height=“749” Width=“1010”>
<Grid>
<my:WpfMap x:Name=“wpfMap1” Margin=“24,22,0,0” HorizontalAlignment=“Left” VerticalAlignment=“Top” Width=“950” Height=“650”></my:WpfMap>
</Grid>
</Window>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Window1.xaml.cs code:
NOTE:- All instances of wpfMap1 give the error ‘The name wpfMap1 does not exist in the current context’
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.DesktopEdition;
using ZedGraph;
namespace MapSuiteTest
{
///
/// Interaction logic for Window1.xaml
///
public partial class Window1 : Window
{
private delegate Bitmap ToUIThreadDelegate(ZedGraphDrawingEventArgs e);
public Window1()
{
InitializeComponent(); <— Get message here - “The name InitializeComponent does not exist in this context”
}
private void Window1_Load(object sender, RoutedEventArgs e)
{
wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
wpfMap1.CurrentExtent = new RectangleShape(-143.4, 109.3, 116.7, -76.3);
wpfMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@“C:\Murty\cities\Countries02.shp”);
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay worldOverlay = new LayerOverlay();
worldOverlay.Layers.Add(“WorldLayer”, worldLayer);
wpfMap1.Overlays.Add(“WorldOverlay”, worldOverlay);
wpfMap1.Refresh();
}
private void zedGraphStyle_ZedGraphDrawing(object sender, ZedGraphDrawingEventArgs e)
{
e.Bitmap = (Bitmap)Dispatcher.Invoke(new ToUIThreadDelegate(ZedGraphDrawing), new object[] { e });
}
private Bitmap ZedGraphDrawing(ZedGraphDrawingEventArgs e)
{
double scale = ExtentHelper.GetScale(wpfMap1.CurrentExtent, (float)wpfMap1.Width, GeographyUnit.DecimalDegree);
// Change the size of the graph based on the scale. It will get bigger as you zoom in.
int graphHeight = Convert.ToInt32(1400000000 / scale);
LayerOverlay staticOverlay = (LayerOverlay)wpfMap1.Overlays[“CitiesOverlay”];
ChangeLabelPosition(((ShapeFileFeatureLayer)staticOverlay.Layers[“Cities”]), graphHeight);
ZedGraphControl zedGraph = new ZedGraphControl();
zedGraph.Size = new System.Drawing.Size(graphHeight, graphHeight);
zedGraph.GraphPane.Fill.Type = FillType.None;
zedGraph.GraphPane.Chart.Fill.Type = FillType.None;
zedGraph.GraphPane.Border.IsVisible = false;
zedGraph.GraphPane.Chart.Border.IsVisible = false;
zedGraph.GraphPane.XAxis.IsVisible = false;
zedGraph.GraphPane.YAxis.IsVisible = false;
zedGraph.GraphPane.Legend.IsVisible = false;
zedGraph.GraphPane.Title.IsVisible = false;
PieItem pieItem1 = zedGraph.GraphPane.AddPieSlice(Convert.ToDouble(e.Feature.ColumnValues[“WHITE”], CultureInfo.InvariantCulture), GetColorFromGeoColor(GeoColor.StandardColors.LightBlue), 0f, “White”);
pieItem1.LabelDetail.IsVisible = false;
PieItem pieItem2 = zedGraph.GraphPane.AddPieSlice(Convert.ToDouble(e.Feature.ColumnValues[“ASIAN”], CultureInfo.InvariantCulture), GetColorFromGeoColor(GeoColor.StandardColors.LightGreen), 0f, “Asian”);
pieItem2.LabelDetail.IsVisible = false;
pieItem2.Displacement = 0.2;
zedGraph.AxisChange();
return zedGraph.GraphPane.GetImage();
}
private static void ChangeLabelPosition(ShapeFileFeatureLayer shapeFileLayer, int graphHeight)
{
((TextStyle)shapeFileLayer.ZoomLevelSet.ZoomLevel01.CustomStyles[1]).XOffsetInPixel = -20;
((TextStyle)shapeFileLayer.ZoomLevelSet.ZoomLevel01.CustomStyles[1]).YOffsetInPixel = Convert.ToSingle(graphHeight * 0.4);
}
private static System.Drawing.Color GetColorFromGeoColor(GeoColor geoColor)
{
return System.Drawing.Color.FromArgb(geoColor.AlphaComponent, geoColor.RedComponent, geoColor.GreenComponent, geoColor.BlueComponent);
}
}
}
NOTE: If I remove the references to the ZedGraph.dll & ZedGraphStyleExtension.dll in my project and comment out all the ZedGraph related code above, the map control runs fine.
Appreciate your help!
Vikram