Hi James,It's been a while since I've looked at this part of my project but here is what I ended up doing. Also, I don't think I was actually getting an error - I think it was just that nothing happened on the updates. Hopefully this helps you. I found this in another post from an ESRI developer in a forum: "While your Map can inherit the DataContext of your UserControl, GraphicsLayer will not. GraphicsLayer, unlike Map or any other UIElement, does not have a DataContext and will therefore fail to resolve this type of Binding." So what I did was to define the map and all of its components in the C# as follows (some of my names are different than my original post b/c that was a prototype - I did have some other issues when I integrated the prototype so I'm hoping that I'm answering your question and not a different problem I had): C# that replaces the .xaml code in the View - this is in the ViewModel of the piece of my project that creates a map report
Map myMap = new Map();
myMap.WrapAround = true;
myMap.ZoomFactor = 1.2;
//street map
ArcGISTiledMapServiceLayer sl = new ArcGISTiledMapServiceLayer();
sl.Url = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
myMap.Layers.Add(sl);
//add the points layer to the map
List<string> pointsMapTipLabels = new List<string>() { "Info" };
myMap.Layers.Add(((Geospatial_ViewModel)tileViewModel.ContentViewModel).addGraphicsLayer("MyPointsList", "IsPointsLayerVisible", pointsMapTipLabels));
tileContentView.Content = myMap;
Here is the addGraphicsLayer() function (this is in the map ViewModel):
//This adds a layer containing WACs to the map; pass in the name of the wac list and
// the name of the boolean that controls visibility for binding
public GraphicsLayer addGraphicsLayer(string list, string isGridVis, List<string> mapTips)
{
GraphicsLayer layer = new GraphicsLayer();
//list binding
Binding listBinding = new Binding(list);
listBinding.Source = this;
listBinding.Mode = System.Windows.Data.BindingMode.TwoWay;
BindingOperations.SetBinding(layer, GraphicsLayer.GraphicsProperty, listBinding);
//list visibility binding - controls whether thepoints are visible
Binding listVisBinding = new Binding(isGridVis);
listVisBinding.Source = this;
listVisBinding.Mode = BindingMode.TwoWay;
BindingOperations.SetBinding(layer, GraphicsLayer.VisibleProperty, listVisBinding);
//map tips
MapTip mt = new MapTip();
Grid mtgrid = new Grid();
Color lightYellow = getColorFromHexString("FFFFFFE0");
mtgrid.Background = new SolidColorBrush(lightYellow);
System.Windows.Thickness thOne = new Thickness();
thOne.Bottom = thOne.Left = thOne.Right = thOne.Top = 1;
mtgrid.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.Black), BorderThickness = thOne });
StackPanel mtpanel = new StackPanel();
System.Windows.Thickness thFive = new Thickness();
thFive.Bottom = thFive.Left = thFive.Right = thFive.Top = 5;
mtpanel.Margin = thFive;
mtpanel.Orientation = Orientation.Vertical;
mtgrid.Children.Add(mtpanel);
foreach (string tip in mapTips)
{
mtpanel.Children.Add(createMapTipTextBlock(tip));
}
layer.MapTip = mtgrid;
return layer;
}
This is all I have in the map View (.xaml file). I am using a ComponentOne tile to display different types of reports. In most cases, the content of the TileItem gets set to the View. This works when my report is a chart but when the report is the ESRI map, it does not so there is basically nothing in the map's .xaml View file.
<UserControl.Resources>
<esriConverters:DictionaryConverter x:Key="MyDictionaryConverter" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot"
Background="White">
</Grid>
</UserControl>
This is the list of points that is used for the binding (in the map ViewModel):
private GraphicCollection myPointsList;
public GraphicCollection MyPointsList
{
get { return myPointsList; }
set
{
myPointsList = value;
RaisePropertyChanged("MyPointsList");
}
}
Then in the map Model, when my query results come back, I update MyPointsList:
GraphicCollection glist = new GraphicCollection();
SpatialReference sref = new SpatialReference(4326);
SolidColorBrush pointColor;
double prevLat = 0.0;
double prevLon = 0.0;
double maxValue = 0.0;
//loop through points returned
for (int x = 0; x < e.Result.geoData.Count(); x++)
{
double lat = e.Result.geoData.Latitude;
double lon = e.Result.geoData.Longitude;
string name = e.Result.Name;
double value = e.Result.MeasureValues;
Graphic g = new Graphic()
{
Geometry = new MapPoint(lon, lat, sref)
};
g.Symbol = new SimpleMarkerSymbol()
{
Color = new SolidColorBrush(Colors.Red),
Size = 18,
Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle
};
//mouse over data
g.Attributes.Add("Info", name + ": " + value.ToString() + " " + viewModel.MeasureSelected.Name);
glist.Add(g);
} //end for each point
viewModel.MyPointsList = glist;
Hopefully this helps and isn't too confusing! I tried to remove the non-relevant code so you could see what the binding is doing easliy. Good luck!