后台添加MapTip

         两大部分:

第一部分:

原文地址:http://bbs.esrichina-bj.cn/ESRI/thread-83725-1-1.html

在xaml中写死的话可以如下:
<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>
      <StackPanel>
      <Button x:Name="charttype" Width="10" Height="10"/>
...........


在后台代码中,需要动态生成MapTip
MapTip tip = new MapTip();
现在需要在MapTip中显示一个button  
怎么没有tip.child 这样的属性呢?

问题:在后台代码中生成的MapTip如何放置button

如果連Maptip也完全由代碼生成的話,可以試試

  1. private void runTest()
  2.         {
  3.             Grid grid = new Grid();
  4.             Button button = new Button();
  5.             button.Content = "test Button";
  6.             button.Width = 100;
  7.             button.Height = 20;
  8.             button.Click += new RoutedEventHandler(button_Click);
  9.             grid.Children.Add(button);
  10.             graphicsLayer.MapTip = grid;            
  11.         }
复制代码

如果本來就有Maptip的話,可以在Maptip裏的第一層設像MouseEnter的事件
比如說Maptip裏是Border的話,就加個

  1. private void Border_MouseEnter(object sender, MouseEventArgs e)
  2.         {
  3.             Border border = sender as Border;
  4.             Button button = new Button();
  5.             button.Width = 30;
  6.             button.Height = 20;
  7.             button.Click += new RoutedEventHandler(button_Click);
  8.             Grid grid = border.Child as Grid;
  9.             grid.Children.Add(button);
  10.         }

應該是可行的

第二部分 :     

                 //Grid grid = new Grid();

                //Button button = new Button();

                //button.Content = "test Button";

                //button.Width = 100;

                //button.Height = 20;

                //button.Click += new RoutedEventHandler(button_Click);

                //grid.Children.Add(button);

                //graphicsLayer.MapTip = grid;

                //MapTip mymaptip = myLayoutRoot.Resources["MyMapTip"] as MapTip;
                //MapTip mymaptip2 = new MapTip();
                //mymaptip.GraphicsLayer = this.graphicsLayer;
                //mymaptip2.GraphicsLayer = this.graphicsLayer;
                //mymaptip.Title = "9999";
                //mymaptip2.Title = "9999";
                //this.graphicsLayer.MapTip = mymaptip;
                //this.graphicsLayer.MapTip = mymaptip2;

关键是 【】

MyBinding.Path = new PropertyPath("[DEVICENAME]");

 Binding MyBinding = new Binding();
                MyBinding.Path = new PropertyPath("[DEVICENAME]");
                MyBinding.Mode = BindingMode.OneWay;
                //MyBinding.Source = graphicsLayer.Graphics;
                MapTip mymaptip = new MapTip();
                mymaptip.GraphicsLayer = this.graphicsLayer;
                mymaptip.AllowDrop = true;
                mymaptip.SetBinding(MapTip.TitleProperty, MyBinding);
                mymaptip.VerticalOffset = 100;
                mymaptip.HorizontalOffset = 100;
                this.graphicsLayer.MapTip = mymaptip;
                this.graphicsLayer.Refresh();

你可能感兴趣的:(map)