ArcGIS Runtime SDK for .NET Samples

ArcGIS token challenge

Loading

Code

<UserControl x:Class="ArcGISRuntime.WPF.Samples.TokenSecuredChallenge.TokenSecuredChallenge"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid x:Name="layoutGrid">
        <esri:MapView x:Name="MyMapView">
            <esri:Map>
                <!-- This layer is public and does not require credentials -->
                <esri:ArcGISTiledLayer Name="World Street Map - Public"
					Source="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
                <!-- This layer is secured with ArcGIS tokens and requires a login -->
                <!--username: user1 | password: user1-->
                <esri:ArcGISMapImageLayer Name="USA - Secure"
					Source="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA_secure_user1/MapServer" />
            </esri:Map>
        </esri:MapView>

        <!-- Login UI -->
        <Border x:Name="loginPanel"
				Background="White" BorderBrush="Black" BorderThickness="1" 
				Margin="30" Padding="20"
				HorizontalAlignment="Center" VerticalAlignment="Top" 
				Visibility="Collapsed">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="150" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" 
                           Margin="0,0,0,8"
						   TextWrapping="Wrap" 
                           Text="{Binding ServiceUrl, StringFormat='Login to: {0}'}" />
                <TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" 
                           Margin="0,0,0,8"
						   TextWrapping="Wrap" 
                           Text="Username and Password are user1/user1" />
                <TextBlock Grid.Row="2" Grid.Column="0" 
                           Margin="2" 
                           VerticalAlignment="Center" 
                           Text="Username" />
                <TextBox Grid.Row="2" Grid.Column="1" 
                         Margin="2" 
                         Text="{Binding UserName, UpdateSourceTrigger=PropertyChanged}" />
                <TextBlock Grid.Row="3" Grid.Column="0" 
                           Margin="2" 
                           VerticalAlignment="Center" 
                           Text="Password" />
                <!-- For simplicity, the password is visible in this example. You can use a PasswordBox to mask the password text,
                     but it complicates data binding. See this discussion for details: http://stackoverflow.com/questions/1483892/how-to-bind-to-a-passwordbox-in-mvvm -->
                <TextBox Grid.Row="3" Grid.Column="1" 
                         Margin="2" 
                         Text="{Binding Password, UpdateSourceTrigger=PropertyChanged}" />
                <Button Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" 
                        Margin="0,12,0,0" 
						HorizontalAlignment="Center" 
                        Content="Login and Load Layer" 
                        IsDefault="True"
						Click="LoginButtonClick" />
                <TextBlock Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" 
                           Margin="8,12,8,0" 
						   Foreground="Red" 
                           TextWrapping="Wrap" 
                           Text="{Binding ErrorMessage}">
                    <TextBlock.Style>
                        <Style TargetType="{x:Type TextBlock}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ErrorMessage}" Value="">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
            </Grid>
        </Border>

        <!-- Layer listing with status -->
        <Border Background="White" BorderBrush="Black" BorderThickness="2" 
                Margin="30" 
                MaxWidth="500"
				HorizontalAlignment="Right" VerticalAlignment="Top">
            <StackPanel>
                <TextBlock FontSize="14" FontWeight="Bold"
                           Margin="4" 
                           Text="Map Layers (with status)" />
                <ListView x:Name="listLayerStatus" 
                          Padding="6" 
                          ItemsSource="{Binding ElementName=MyMapView, Path=Map.AllLayers}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding Name}" 
                                           HorizontalAlignment="Left" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Margin="20,0,0,5" 
                                               FontWeight="Bold">
                                        <TextBlock.Style>
                                            <Style TargetType="{x:Type TextBlock}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding LoadStatus}" 
                                                                 Value="2">
                                                        <Setter Property="Foreground" Value="Red" />
                                                        <Setter Property="Text" Value="Access Denied" />
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding LoadStatus}" Value="0">
                                                        <Setter Property="Foreground" Value="Green" />
                                                        <Setter Property="Text" Value="Access Granted" />
                                                    </DataTrigger>
                                                </Style.Triggers>

                                                <Style.Setters>
                                                    <Setter Property="Foreground" Value="Black" />
                                                    <Setter Property="Text" Value="Initializing" />
                                                </Style.Setters>
                                            </Style>
                                        </TextBlock.Style>
                                    </TextBlock>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackPanel>
        </Border>
    </Grid>
</UserControl>


In this topic
  1. Code