Interaction Options

Download Samples Repository

Description

This sample shows how to change interaction settings that controls the MapView.

"Desktop" "Store" "Phone" Available for Desktop, Store, Phone

Sample Code

<UserControl 
	x:Class="ArcGISRuntime.Samples.Desktop.InteractionOptionsSample"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:sys="clr-namespace:System;assembly=mscorlib"
		xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
		<Grid>
			<esri:MapView x:Name="MyMapView" LayerLoaded="MyMapView_LayerLoaded">
			<!-- Setting values explicitly -->
			<!--
			<esri:MapView.InteractionOptions>
				<esri:InteractionOptions IsEnabled="True">
					<esri:InteractionOptions.PanOptions>
						<esri:PanOptions
							IsEnabled="True"
							IsDragEnabled="True"
							IsFlickEnabled="True"
							IsKeyboardEnabled="True"
							IsStylusEnabled="True">
						</esri:PanOptions>
					</esri:InteractionOptions.PanOptions>
				</esri:InteractionOptions>			
			</esri:MapView.InteractionOptions>
			-->
				<esri:Map>
					<esri:ArcGISTiledMapServiceLayer ID="Basemap" 
								ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
				</esri:Map>
			</esri:MapView>

			<Border Background="White" BorderBrush="Black" BorderThickness="1" Margin="30" 
							Padding="20" HorizontalAlignment="Right" VerticalAlignment="Top">
				<Border.Effect>
					<DropShadowEffect />
				</Border.Effect>
				<StackPanel>
					<TextBlock Text="Interaction options" HorizontalAlignment="Center" FontSize="16" Margin="10" FontWeight="Bold"/>
					<StackPanel Margin="10,0">
						<CheckBox Content="IsEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.IsEnabled}"/>
					</StackPanel>
					<StackPanel Margin="10,0">
						<TextBlock Text="Pan options" HorizontalAlignment="Left" FontSize="12" Margin="0,10" FontWeight="Bold"/>
						<CheckBox Content="IsEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.PanOptions.IsEnabled}"/>
						<CheckBox Content="IsDragEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.PanOptions.IsDragEnabled}"/>
						<CheckBox Content="IsFlickEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.PanOptions.IsFlickEnabled}"/>
						<CheckBox Content="IsKeyboardEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.PanOptions.IsKeyboardEnabled}"/>
						<CheckBox Content="IsStylusEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.PanOptions.IsStylusEnabled}"/>
					</StackPanel>
					<StackPanel Margin="10,0">
						<StackPanel.Resources>
							<ObjectDataProvider x:Key="MouseWheelOptionValues" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
								<ObjectDataProvider.MethodParameters>
									<x:Type TypeName="esri:MouseWheelDirection"/>
								</ObjectDataProvider.MethodParameters>
							</ObjectDataProvider>
						</StackPanel.Resources>
						<TextBlock Text="Zoom options" HorizontalAlignment="Left" FontSize="12" Margin="0,10" FontWeight="Bold"/>
						<CheckBox Content="IsEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.ZoomOptions.IsEnabled}"/>
						<CheckBox Content="IsDoubleTappedEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.ZoomOptions.IsDoubleTappedEnabled}"/>
						<CheckBox Content="IsKeyboardEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.ZoomOptions.IsKeyboardEnabled}"/>
						<CheckBox Content="IsMouseWheelEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.ZoomOptions.IsMouseWheelEnabled}"/>
						<CheckBox Content="IsPinchEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.ZoomOptions.IsPinchEnabled}"/>
						<CheckBox Content="IsTwoFingerTapEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.ZoomOptions.IsTwoFingerTapEnabled}"/>
						<CheckBox Content="IsZoomBoxEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.ZoomOptions.IsZoomBoxEnabled}"/>
						<CheckBox Content="IsStylusEnabled" IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.ZoomOptions.IsStylusEnabled}"/>
						<StackPanel Margin="0,5">
						<TextBlock Text="MouseWheelZoomInDirection"/>
							<ComboBox Margin="10,2" ItemsSource="{Binding Source={StaticResource MouseWheelOptionValues}}" 
												SelectedItem="{Binding ElementName=MyMapView, Path=InteractionOptions.ZoomOptions.MouseWheelZoomInDirection}">
							</ComboBox>
						</StackPanel>
					</StackPanel>

					<StackPanel Margin="10,0">
						<TextBlock Text="Rotation options" HorizontalAlignment="Left" FontSize="12" Margin="0,10" FontWeight="Bold"/>
						<CheckBox Name="RotationEnabled" Content="IsEnabled" Margin="0,0,0,5"
											IsChecked="{Binding ElementName=MyMapView, Path=InteractionOptions.RotationOptions.IsEnabled}" />
						<TextBlock Text="{Binding ElementName=rotationSlider, Path=Value, StringFormat='Rotation: {0:0.0}'}" 
											 Margin="4,0" FontWeight="Bold" />
						<Slider x:Name="rotationSlider" Margin="4" ValueChanged="rotationSlider_ValueChanged" Orientation="Horizontal" Width="100" 
										IsSnapToTickEnabled="True" TickPlacement="BottomRight" TickFrequency="5" Minimum="0" Maximum="360"
										Visibility="{Binding Path=IsChecked, ElementName=RotationEnabled, Converter={StaticResource BooleanToVisibilityConverter}}"
										Value="{Binding Rotation, ElementName=MyMapView, Mode=OneWay, Delay=50}" />
					</StackPanel>
				</StackPanel>
			</Border>
		</Grid>
</UserControl>
using Esri.ArcGISRuntime.Controls;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
    /// <summary>
    /// This sample shows how to change interaction settings that controls the MapView.
    /// </summary>
    /// <title>Interaction Options</title>
    /// <category>Mapping</category>
    public partial class InteractionOptionsSample : UserControl
    {
        public InteractionOptionsSample()
        {
            InitializeComponent();
        }

        private void MyMapView_LayerLoaded(object sender, LayerLoadedEventArgs e)
        {
            if (e.LoadError == null)
                return;

            MessageBox.Show(
                string.Format("Error when loading layer. {0}", e.LoadError.ToString()),
                              "Error loading layer");
        }

        private void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            Debug.WriteLine("MapViewTapped");
        }

        private void MyMapView_MapViewDoubleTapped(object sender, MapViewInputEventArgs e)
        {
            Debug.WriteLine("MapViewDoubleTapped");
        }

        private void MyMapView_MapViewHolding(object sender, MapViewInputEventArgs e)
        {
            Debug.WriteLine("Holding");
        }

        private void rotationSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (MyMapView.InteractionOptions.RotationOptions.IsEnabled)
            {
                MyMapView.SetRotation(e.NewValue);
            }
        }
    }
}
Feedback on this topic?