Add Interactively Online

This sample demonstrates adding graphics through user interaction. The sample uses the Toolkit's Toolbar control and the Draw object to provide graphic drawing tools. In the sample's code-behind, an event handler for the Toolbar's ItemClicked event is used to parse which tool was clicked and initialize the Draw object accordingly.
Download Sample Application<UserControl x:Class="ArcGISWPFSDK.DrawGraphics" 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"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <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> <Style TargetType="Button"> <Setter Property="Background" Value="#FF1F3B53"/> <Setter Property="Foreground" Value="#FF000000"/> <Setter Property="Padding" Value="3"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="BorderBrush"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFA3AEB9" Offset="0"/> <GradientStop Color="#FF8399A9" Offset="0.375"/> <GradientStop Color="#FF718597" Offset="0.375"/> <GradientStop Color="#FF617584" Offset="1"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"/> <VisualState x:Name="MouseOver"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundAnimation"/> <ColorAnimation Duration="0" To="#F2FFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> <ColorAnimation Duration="0" To="#CCFFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> <ColorAnimation Duration="0" To="#7FFFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> </Storyboard> </VisualState> <VisualState x:Name="Pressed"> <Storyboard> <ColorAnimation Duration="0" To="#D8FFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> <ColorAnimation Duration="0" To="#C6FFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> <ColorAnimation Duration="0" To="#8CFFFFFF" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> <ColorAnimation Duration="0" To="Red" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient"/> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="MyStates"> <VisualState x:Name="Selected"> <Storyboard> <ColorAnimation Duration="0" To="Red" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Background"/> </Storyboard> </VisualState> <VisualState x:Name="UnSelected"> <Storyboard> <ColorAnimation Duration="0" To="White" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Background"/> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border x:Name="Background" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="White" CornerRadius="3"> <Grid Background="{TemplateBinding Background}" Margin="1"> <Border x:Name="BackgroundAnimation" Background="#FF448DCA" Opacity="0"/> <Rectangle x:Name="BackgroundGradient"> <Rectangle.Fill> <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0"> <GradientStop Color="#FFFFFFFF" Offset="0"/> <GradientStop Color="#F9FFFFFF" Offset="0.375"/> <GradientStop Color="#E5FFFFFF" Offset="0.625"/> <GradientStop Color="#C6FFFFFF" Offset="1"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> </Grid> </Border> <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <esri:SimpleLineSymbol x:Key="DrawLineSymbol" Color="Green" Width="4" /> <esri:SimpleFillSymbol x:Key="DrawFillSymbol" Fill="#3300FF00" BorderBrush="Green" BorderThickness="2" /> <esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Color="Red" Size="12" Style="Circle" /> <esri:SimpleLineSymbol x:Key="DefaultLineSymbol" Color="Red" Width="4" /> <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" Fill="#33FF0000" BorderBrush="Red" BorderThickness="2" /> <esri:Editor x:Key="MyEditor" LayerIDs="MyGraphicsLayer" /> </Grid.Resources> <esri:Map WrapAround="True" x:Name="MyMap" Extent="-15000000,2000000,-7000000,8000000" Loaded="MyMap_Loaded"> <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> <esri:GraphicsLayer ID="MyGraphicsLayer" MouseLeftButtonUp="GraphicsLayer_MouseLeftButtonUp" /> </esri:Map> <Border Background="{StaticResource PanelGradient}" BorderThickness="1" CornerRadius="5" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10" BorderBrush="{StaticResource PanelGradient}"> <Border.Effect> <DropShadowEffect/> </Border.Effect> <Grid Margin="10" Background="White"> <StackPanel Orientation="Vertical"> <StackPanel x:Name="MyStackPanel" Orientation="Horizontal" Width="600" Height="60"> <Button Tag="DrawPoint" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a point"> <Image Source="/Assets/images/DrawPoint.png" Margin="2" /> </Button> <Button Tag="DrawPolyline" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a polyline"> <Image Source="/Assets/images/DrawPolyline.png" Margin="2" /> </Button> <Button Tag="DrawPolygon" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a polygon"> <Image Source="/Assets/images/DrawPolygon.png" Margin="2" /> </Button> <Button Tag="DrawRectangle" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a rectangle"> <Image Source="/Assets/images/DrawRectangle.png" Margin="2" /> </Button> <Button Tag="DrawFreehand" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a freehand line"> <Image Source="/Assets/images/DrawFreehand.png" Margin="2" /> </Button> <Button Tag="DrawArrow" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add an arrow"> <Image Source="/Assets/images/DrawArrow.png" Margin="2" /> </Button> <Button Tag="DrawTriangle" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a triangle"> <Image Source="/Assets/images/DrawTriangle.png" Margin="2" /> </Button> <Button Tag="DrawCircle" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a circle"> <Image Source="/Assets/images/DrawCircle.png" Margin="2" /> </Button> <Button Tag="DrawEllipse" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add an ellipse"> <Image Source="/Assets/images/DrawEllipse.png" Margin="2" /> </Button> <Button Tag="ClearStopDraw" Margin="5" Click="Tool_Click" Style="{x:Null}" ToolTipService.ToolTip="Clear graphics"> <Image Source="/Assets/images/StopDraw.png" Margin="2" /> </Button> </StackPanel> <TextBlock x:Name="StatusTextBlock" Text="" FontWeight="Bold" HorizontalAlignment="Center"/> <CheckBox x:Name="EnableEditVerticesScaleRotate" Content="Click on geometry to edit" IsChecked="False" Foreground="Black" FontWeight="Bold" Margin="10,5,5,5" /> </StackPanel> </Grid> </Border> </Grid> </UserControl>
5/16/2014