在C#代码后面添加一些像Textblock一样的控件作为ItemSource

时间:2016-07-26 09:07:30

标签: xaml windows-8.1 arcgis esri arcgis-runtime

我有ArcGIS Windows Runtime Esri项目,我的XAML是这样的:

<esri:MapView x:Name="MyMapView">

<esri:MapView.Overlays>
    <esri:OverlayItemsControl>
            <Grid MaxWidth="350">
                <TextBlock Text="Details" FontWeight="Bold" Margin="0,0,0,4" />
            </Grid>
        </Border>
    </esri:OverlayItemsControl>
</esri:MapView.Overlays>

</esri:MapView>

我想在代码中添加OverlaysOverlayItemsControl而不是XAML。

我在C#代码背后试过这样的事情:

MapView mapView = new MapView();
mapView.Overlays.ItemsSource = new List<object> { new TextBlock() { Text = "Details", Name = "overLay" } };
mapView.Overlays.Items.Clear();
mapView.Overlays.Items.Add(MyMapView.Overlays.ItemsSource);

但它给出了错误。我不知道到底出了什么问题。

如何从Esri Overlays, Grid, Textblock内部的代码中添加这些控件MapView

1 个答案:

答案 0 :(得分:0)

我通过代码在给定的地图点(mp)绘制文本框:

TextBox tbMsg = new TextBox();
tbMsg.Width = 250;
tbMsg.Height = 200;
tbMsg.Text = "Your Message";

tbMsg.GotFocus += Tb_GotFocus;
tbMsg.Visibility = Visibility.Visible;


Esri.ArcGISRuntime.Controls.MapView.SetViewOverlayAnchor(tbMsg, mp);
MyMapView.Overlays.Items.Add(tbMsg);