Bing Routing

This sample demonstrates using the ESRI.ArcGIS.Client.Toolkit.Bing Routing class to perform optimal routing along a highway network between two or more points using Microsoft Bing services. The results of the routing operation are display back both as written travel directions and graphic polylines on the map.

Download Sample Application
XAML C# VB.NET
<UserControl x:Class="ArcGISWPFSDK.BingRouting"
    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/client/2009"
    xmlns:bing="clr-namespace:ESRI.ArcGIS.Client.Bing;assembly=ESRI.ArcGIS.Client.Bing">
    <Grid x:Name="LayoutRoot">
        <Grid.Resources>
            <Style x:Key="Link_Button" TargetType="Button">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <TextBlock TextDecorations="Underline"> 
								<ContentPresenter/>
                            </TextBlock>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="Foreground" Value="Blue" />
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Foreground" Value="Red" />
                    </Trigger>
                </Style.Triggers>
            </Style>
            <ControlTemplate x:Key="CompositeSymbol">
                <Grid>
                    <Ellipse Fill="{Binding Symbol.Color}" Width="{Binding Symbol.Size}" Height="{Binding Symbol.Size}" Stroke="Black" StrokeThickness="1" />
                    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"
                  Text="{Binding Path=Attributes[StopNumber]}"
                  FontSize="9" Margin="0" FontWeight="Bold" Foreground="Black" />
                </Grid>
            </ControlTemplate>
            <esri:SimpleMarkerSymbol x:Key="UserStopSymbol" Size="20" Style="Circle" Color="Salmon" ControlTemplate="{StaticResource CompositeSymbol}" />
            <esri:SimpleMarkerSymbol x:Key="ResultStopSymbol" Size="20" Color="GreenYellow" ControlTemplate="{StaticResource CompositeSymbol}" />
            <esri:SimpleLineSymbol x:Key="RoutePathSymbol" Style="Solid" Width="4" Color="YellowGreen" />
            <LinearGradientBrush x:Key="PanelGradient" EndPoint="0.5,1" StartPoint="0.5,0">
                <LinearGradientBrush.RelativeTransform>
                    <TransformGroup>
                        <ScaleTransform CenterY="0.5" CenterX="0.5"/>
                        <SkewTransform CenterY="0.5" CenterX="0.5"/>
                        <RotateTransform Angle="176" CenterY="0.5" CenterX="0.5"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </LinearGradientBrush.RelativeTransform>
                <GradientStop Color="#FF145787" Offset="0.16"/>
                <GradientStop Color="#FF3D7FAC" Offset="0.502"/>
                <GradientStop Color="#FF88C5EF" Offset="0.984"/>
            </LinearGradientBrush>
        </Grid.Resources>
        <esri:Map x:Name="MyMap" WrapAround="True" Background="#FFE3E3E3">
            <esri:GraphicsLayer ID="RouteResultsGraphicsLayer" />
            <esri:GraphicsLayer ID="WaypointGraphicsLayer" />
        </esri:Map>
        <esri:Attribution Layers="{Binding ElementName=MyMap, Path=Layers}" Margin="10" VerticalAlignment="Top" />
        <Grid Name="BingKeyGrid" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,15,0">
            <Rectangle Stroke="Gray"  RadiusX="10" RadiusY="10" Fill="{StaticResource PanelGradient}" Margin="0,0,0,5" >
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>
            <Rectangle Fill="#DDFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10" />
            <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="20,20,20,20">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="2" >
                    <TextBlock FontWeight="Bold" HorizontalAlignment="Center" Text="Enter Bing Key" Margin="2" Foreground="Black"/>
                    <Button Style="{StaticResource Link_Button}" Margin="2" Content="(Get Bing Key)" Click="Button_Click"/>
                </StackPanel>
                <TextBox x:Name="BingKeyTextBox" Width="250" HorizontalAlignment="Right" Margin="0,2,0,2"
                        TextChanged="BingKeyTextBox_TextChanged" />
                <TextBlock Name="InvalidBingKeyTextBlock" Text="Invalid Key" Foreground="Red"
                        Margin="0,2,0,2" HorizontalAlignment="Center" Visibility="Collapsed"/>
                <Button Name="LoadMapButton" Content="Load Map" Width="100" Margin="0,5,0,10" IsEnabled="False" 
                        HorizontalAlignment="Center" Click="LoadMapButton_Click" />
            </StackPanel>
        </Grid>
        <StackPanel Name="RouteGrid" HorizontalAlignment="Right" VerticalAlignment="Top" MaxWidth="250" Visibility="Collapsed">
            <Grid VerticalAlignment="Top" Margin="10" >
                <Rectangle Fill="{StaticResource PanelGradient}" Stroke="Gray" RadiusX="10" RadiusY="10" Margin="0" >
                    <Rectangle.Effect>
                        <DropShadowEffect/>
                    </Rectangle.Effect>
                </Rectangle>
                <StackPanel Margin="10">
                    <TextBlock Text="Click on map to define waypoints. Click the Solve Route button to generate a route." 
                           TextWrapping="Wrap" Foreground="White" Width="225" />
                    <Button x:Name="RouteButton" Content="Solve Route" Margin="2" Width="100" Height="20" HorizontalAlignment="Center" 
                            Click="RouteButton_Click"/>
                    <Button x:Name="ClearRouteButton" Content="Clear Route" Margin="2" Width="100" Height="20" HorizontalAlignment="Center" 
                            Click="ClearRouteButton_Click" />
                </StackPanel>
            </Grid>
            <Grid x:Name="DirectionsGrid" VerticalAlignment="Top" Margin="10" Visibility="Collapsed" >
                <Rectangle Fill="{StaticResource PanelGradient}" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0" >
                    <Rectangle.Effect>
                        <DropShadowEffect/>
                    </Rectangle.Effect>
                </Rectangle>
                <StackPanel Orientation="Vertical" HorizontalAlignment="Left" Margin="5" >
                    <TextBlock x:Name="DirectionsTitleTextBlock" Margin="5,0,0,5" Text="Directions" FontSize="12" Foreground="White" FontWeight="Bold" />
                    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" MaxWidth="250" MaxHeight="300" >
                        <TextBlock x:Name="DirectionsContentTextBlock" Foreground="White" />
                    </ScrollViewer>
                </StackPanel>
            </Grid>
        </StackPanel>
    </Grid>
</UserControl>

Sample code usage restrictions
5/16/2014