I recently need to develop a ArcGIS system in Silverlight C# Application via visual studio community 2022. The main problem I meet now is to set the GraphicsLayer in map, and show the map in the layout. And since silverlight is no more support by ArcGIS, therefore, there is hard to find a good instructions for developing ArcGIS in C# silverlight application. The code snippet is as below:
MainPage.xaml:
<UserControl x:Class="SilverlightApplication20230823.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:Anno="http://schemas.microsoft.com/expression/blend/extensions/annotations/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.Resources>
<esri:SimpleLineSymbol x:Key="SLineSymbol" Color="black" Width="1" />
<esri:SimpleFillSymbol x:Key="DrawFillSymbol" Fill="#4C12EEEE" BorderBrush="#FF04F0FB" BorderThickness="2" />
<esri:Map Background="White" HorizontalAlignment="Stretch" x:Key="MapMain" VerticalAlignment="Stretch" WrapAround="True">
<esri:Map.Extent >
<esri:Envelope XMin="278000" YMin="272000" XMax="353000" YMax="2790000">
<esri:Envelope.SpatialReference>
<esri:SpatialReference WKID="102443"/>
</esri:Envelope.SpatialReference>
</esri:Envelope>
</esri:Map.Extent>
<esri:GraphicsLayer ID="MDraw">
</esri:GraphicsLayer>
</esri:Map>
</Grid.Resources>
</Grid>
</UserControl>
and the .cs file is as following:
MainPage.xaml.cs
private Draw MDrawObject;
private Map MapMain = new Map();
public MainPage()
{
MapMain = LayoutRoot.Resources["MapMain"] as Map;
MapMain.HorizontalAlignment = HorizontalAlignment.Stretch;
MapMain.VerticalAlignment = VerticalAlignment.Stretch;
MapMain.WrapAround = true;
MapMain.SnapToLevels = true;
MapMain.MinimumResolution = 0.235185;
MapMain.MaximumResolution = 264.584;
MapMain.Height = 318;
MapMain.Width = 483;
ArcGISTiledMapServiceLayer glayer;
glayer = new ArcGISTiledMapServiceLayer()
{
Url ="..../TCBaseMap/Land_500/MapServer",
ID = "FDiagram",
Visible = true
};
Map1.Layers.Insert(0, glayer);
MDrawObject = new Draw(MapMain)
{
FillSymbol = LayoutRoot.Resources["DrawFillSymbol"] as FillSymbol,
LineSymbol = LayoutRoot.Resources["SLineSymbol"] as LineSymbol,
DrawMode = DrawMode.Rectangle
};
}
Since the class of ESRI.ArcGIS.Client is used in .cs, and in .xaml, the map is defined in <Grid.Resources>, so there is no declaration and binding for map's location to layout, so after compile, the system doesn't show any map layer in screen, but other silverlight components are well shown. How to make the map can be shown through the code in MainPage.xaml.cs? Any instruction is highly appreciated, thanks a lot.