後台添加MapTip

來源:互聯網
上載者:User

         兩大部分:

第一部分:

原文地址: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();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.