Add Interactively
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.LocalDrawGraphics" 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> <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" /> <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" Loaded="MyMap_Loaded" Extent="-15000000,2000000,-7000000,8000000" Background="#FFE3E3E3" MinimumResolution="2445.98490512499"> <esri:ArcGISLocalTiledLayer ID="myBaseMap" Path="..\\Data\\TPKs\\Topographic.tpk"/> <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" /> </StackPanel> </Grid> </Border> </Grid> </UserControl>
5/16/2014