Select to view content in your preferred language

MapTips onm graphicsLayer By Code

3041
10
05-05-2011 05:46 AM
MarcoRosa
Emerging Contributor
Hi guys,
i would like to replicate this xaml section code by behind code:


<esri:GraphicsLayer ID="GeocodeResultsGraphicsLayer" >
<esri:GraphicsLayer.MapTip>
  <Grid>
   <Border BorderBrush="Black" CornerRadius="10"  BorderThickness="1" Background="#FFFFE300" />
     <StackPanel Orientation="Vertical" Margin="5">
       <TextBlock x:Name="LocatorText" Text ="{Binding [DisplayName]}" HorizontalAlignment="Left" />
     </StackPanel>
  </Grid>
</esri:GraphicsLayer.MapTip>
</esri:GraphicsLayer>
            
my behind code is that:

GraphicsLayer graphicsLayer = new GraphicsLayer();

TextBox t = new TextBox();
System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
binding.Source = graphicsLayer;
binding.Path = new PropertyPath("[DisplayName]");
t.SetBinding(TextBox.TextProperty, binding);
           
Border border = new Border();
border.BorderThickness = new Thickness(1);
Panel panel = new StackPanel();
panel.Children.Add(t);
border.Child = panel;
           
graphicsLayer.ID = "GeocodeResultsGraphicsLayer";
graphicsLayer.MapTip = border;

..... later in graphicslayer ...

graphic.Attributes.Add("DisplayName", geocodeResult.DisplayName);
graphicsLayer.Graphics.Add(graphic);


Now when i put mouse over graphic objects in graphicsLayer i have no errors but is displayed a maptip whitout name.
I've tried also
binding.Path = new PropertyPath("Attributes[DisplayName]");
but nothing

where's the error ?
Thanks a lot
GD
0 Kudos
10 Replies
EricCreahi
Emerging Contributor
hello!
I have problem with my code, I need your help.
My XAML is :
 <Grid.Resources>
        <esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Color="Red" Size="6" Style="Diamond" />
  </Grid.Resources>

         <esri:Map x:Name="map1" Background="White"   WrapAround="True" Margin="0,22,0,0" Extent="-928323.6071, 502054.310, -295465.584, 1113500.0197"  ZoomFactor="2" IsLogoVisible="False" >
          
                <!--Map Layers-->
                <esri:ArcGISTiledMapServiceLayer ID="BaseMapLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
                <esri:GraphicsLayer ID="MyGraphicsLayer">
                    <esri:GraphicsLayer.MapTip>
                        <Border BorderBrush="DarkGray" CornerRadius="13" BorderThickness="1" Margin="0,0,15,15">
                            <Border.Effect>
                                <DropShadowEffect ShadowDepth="10" BlurRadius="14" Direction="300" />
                            </Border.Effect>
                            <Border CornerRadius="10" Background="#DDFFEEEE" BorderThickness="5" BorderBrush="#77FF0000">
                                <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="10">                                                             
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="Cacao : " FontWeight="Bold" Foreground="#FF0F274E" FontSize="10" VerticalAlignment="Center" />
                                        <TextBlock Text="{Binding [CACAO11_12]}" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                        </Border>
                    </esri:GraphicsLayer.MapTip>
                </esri:GraphicsLayer>
               </esri:Map>
        




in my codebehind is:

 void MyMap_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
           
            
            if (e.PropertyName == "SpatialReference")
            {
           
                map1.PropertyChanged -= MyMap_PropertyChanged;

                _legendGridCollapsed = false;
                _classGridCollapsed = false;

                LegendCollapsedTriangle.MouseLeftButtonUp += Triangle_MouseLeftButtonUp;
                LegendExpandedTriangle.MouseLeftButtonUp += Triangle_MouseLeftButtonUp;

                // Set query where clause to include features with an area greater than 70 square miles.  This 
                // will effectively exclude the District of Columbia from attributes to avoid skewing classifications.
                ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query()
                {
                    Where = "CAFE11_12 > 0 and CACAO11_12 > 0",
                    OutSpatialReference = map1.SpatialReference,
                    ReturnGeometry = true
                };
                query.OutFields.Add("*");
                QueryTask queryTask = new QueryTask("http://services1.arcgis.com/yt621kzsRO05k21r/arcgis/rest/services/PRODUCTION_CACAO/FeatureServer/0");
                queryTask.ExecuteCompleted += (evtsender, args) =>
                {
                    if (args.FeatureSet == null) return;
                        _featureSet = args.FeatureSet;
                        SetRangeValues();
                        _valeurSetRangeValue = true;

                };
                queryTask.ExecuteCompleted += queryTask_ExecuteCompleted;
                queryTask.ExecuteAsync(query);
               
                CreateColorList1();
                CreateThematicList();

               
            }
        }



  void queryTask_ExecuteCompleted(object sender, QueryEventArgs queryArgs)
        {
            if (queryArgs.FeatureSet == null)
                return;

            FeatureSet resultFeatureSet = queryArgs.FeatureSet;
            ESRI.ArcGIS.Client.GraphicsLayer graphicsLayer = map1.Layers["MyGraphicsLayer"] as ESRI.ArcGIS.Client.GraphicsLayer;

            if (resultFeatureSet != null && resultFeatureSet.Features.Count > 0)
            {
                foreach (ESRI.ArcGIS.Client.Graphic graphicFeature in resultFeatureSet.Features)
                {
                    graphicFeature.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                    graphicsLayer.Graphics.Add(graphicFeature);
                }
            }
        }




I don't know watch wrong with it ?
nothing come
0 Kudos