Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

NetworkLink with TreeView

Download Samples Repository

Description

This sample demonstrates how to display KML NetworkLink features and bind them to a TreeView.

"Desktop" Available for Desktop

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.NetworkLinkKML"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
	<Grid>
		<Grid.Resources>
			<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
			<Storyboard x:Key="Storyboard" BeginTime="00:00:00.000" Duration="00:00:1.000" RepeatBehavior="Forever">
				<DoubleAnimation Storyboard.TargetName="RotateImage" 
                             Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" 
                             From="0" To="360" Duration="00:00:01.000" RepeatBehavior="Forever"  />
			</Storyboard>
		</Grid.Resources>

		<esri:MapView x:Name="MyMapView" LayerLoaded="MyMapView_LayerLoaded">
			<esri:Map x:Name="MyMap">
				<esri:ArcGISTiledMapServiceLayer ServiceUri="http://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer"/>
				<esri:KmlLayer SourceUri="http://radar.vlieghinder.nl/"/>
			</esri:Map>
		</esri:MapView>

		<Border x:Name="TreeViewBorder" CornerRadius="5" Background="White" BorderBrush="Black" BorderThickness="2" Margin="5,10,5,5" HorizontalAlignment="Right" VerticalAlignment="Top" Visibility="Visible">
			<StackPanel>
				<TreeView Name="treeView" Width="250" Height="600">
					<TreeView.ItemTemplate>
						<HierarchicalDataTemplate DataType="{x:Type MenuItem}" ItemsSource="{Binding ChildFeatures}">
							<StackPanel Orientation="Horizontal" >
								<Image x:Name="RotateImage" Stretch="Uniform" Source="pack://application:,,,/ArcGISRuntimeSamplesDesktop;component/Assets/Updating.png" RenderTransformOrigin="0.5,0.5" Margin="3" Visibility="{Binding IsUpdating, FallbackValue=Collapsed, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
									<Image.RenderTransform>
										<RotateTransform Angle="0" />
									</Image.RenderTransform>
									<Image.Triggers>
										<EventTrigger RoutedEvent="Image.Loaded">
											<BeginStoryboard Storyboard="{StaticResource Storyboard}" />
										</EventTrigger>
									</Image.Triggers>
								</Image>
								<CheckBox IsChecked="{Binding IsVisible}"/>
								<TextBlock Text="{Binding Name}"/>
							</StackPanel>
						</HierarchicalDataTemplate>
					</TreeView.ItemTemplate>
				</TreeView>
			</StackPanel>
		</Border>
	</Grid>
</UserControl>
using System;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using Esri.ArcGISRuntime.Layers;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Controls;
using System.Windows.Media;
using System.Windows;

namespace ArcGISRuntime.Samples.Desktop
{
	/// <summary>
	/// This sample demonstrates how to display KML NetworkLink features and bind them to a TreeView.
	/// </summary>
	/// <title>NetworkLink with TreeView</title>
	/// <category>Layers</category>
	/// <subcategory>Kml Layers</subcategory>
	public partial class NetworkLinkKML : UserControl
	{
		public NetworkLinkKML()
		{
			InitializeComponent();
		}

		private async void MyMapView_LayerLoaded(object sender, Esri.ArcGISRuntime.Controls.LayerLoadedEventArgs e)
		{
			try
			{
				//Add kml layer to the treeView
				if (e.Layer is KmlLayer)
				{
					ObservableCollection<KmlFeature> kmlFeatureList = new ObservableCollection<KmlFeature>();
					kmlFeatureList.Add((e.Layer as KmlLayer).RootFeature);

					treeView.ItemsSource = kmlFeatureList;

					await MyMapView.SetViewAsync(new MapPoint(570546.04, 6867036.46), 1000000);
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message, "Sample Error");
			}
		}
	}
}
Feedback on this topic?