Solved! Go to Solution.
activeSymbol = new TextSymbol() { Text = "", FontSize = 12, Foreground = new SolidColorBrush(clr), FontFamily = new FontFamily("Arial"), };
void Draw_DrawComplete(object sender, DrawEventArgs e) { GraphicsLayer gl = _Map.Layers[_glayer] as GraphicsLayer; if (_bolText) //if user selected text from drawing options { (_symbol as TextSymbol).Text = txtText.Text; txtText.Text = string.Empty; spText.Visibility = Visibility.Collapsed; } Graphic g = new Graphic() { Geometry = e.Geometry, Symbol = _symbol }; gl.Graphics.Add(g); gl.Refresh(); _Draw.IsEnabled = false; _Draw.DrawMode = DrawMode.None; }
What I've done is set the DrawMode to Point and then put the text the user types in a textbox at that point - code snippet below. Might work for other DrawMode geometry types too, just haven't tried it.void Draw_DrawComplete(object sender, DrawEventArgs e) { GraphicsLayer gl = _Map.Layers[_glayer] as GraphicsLayer; if (_bolText) //if user selected text from drawing options { (_symbol as TextSymbol).Text = txtText.Text; txtText.Text = string.Empty; spText.Visibility = Visibility.Collapsed; } Graphic g = new Graphic() { Geometry = e.Geometry, Symbol = _symbol }; gl.Graphics.Add(g); gl.Refresh(); _Draw.IsEnabled = false; _Draw.DrawMode = DrawMode.None; }
<StackPanel Orientation="Vertical" Margin="3"> <StackPanel x:Name="MyStackPanel" Orientation="Horizontal"> <Button Tag="DrawPoint" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a point"> <Image Source="images/DrawPoint.png" Margin="2" /> </Button> <Button Tag="DrawPolyline" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a polyline"> <Image Source="images/DrawPolyline.png" Margin="2" /> </Button> <Button Tag="DrawPolygon" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a polygon"> <Image Source="images/DrawPolygon.png" Margin="2" /> </Button> <Button Tag="DrawRectangle" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a rectangle"> <Image Source="images/DrawRectangle.png" Margin="2" /> </Button> <Button Tag="DrawFreehand" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a freehand line"> <Image Source="images/DrawFreehand.png" Margin="2" /> </Button> <Button Tag="DrawArrow" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add an arrow"> <Image Source="images/DrawArrow2.png" Margin="2" /> </Button> <Button Tag="DrawTriangle" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a triangle"> <Image Source="images/DrawTriangle2.png" Margin="2" /> </Button> <Button Tag="DrawCircle" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add a circle"> <Image Source="images/DrawCircle2.png" Margin="2" /> </Button> <Button Tag="DrawEllipse" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add an ellipse"> <Image Source="images/DrawEllipse2.png" Margin="2" /> </Button> <Button Tag="EnterText" Margin="5" Click="Tool_Click" ToolTipService.ToolTip="Add text"> <Image Source="images/text.png" Margin="2" /> </Button> <Button Tag="DrawNothing" Margin="5" Click="Tool_Click" Style="{x:Null}" ToolTipService.ToolTip="Unselect Current Tool"> <Image Source="images/dismiss.png" Margin="2" /> </Button> <Button Tag="ClearStopDraw" Margin="5" Click="Tool_Click" Style="{x:Null}" ToolTipService.ToolTip="Clear graphics"> <Image Source="images/StopDraw.png" Margin="2" /> </Button> </StackPanel> <CheckBox x:Name="EnableEditVerticesScaleRotate" Content="Click on geometry to edit" IsChecked="False" Foreground="Black" FontWeight="Bold" Margin="10,5,5,5" /> <TextBox x:Name="txtText" Text="" /> </StackPanel>
private void MyDrawObjectGraphic_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args) { if (_bolText) //if user selected text from drawing options { (_activeSymbol as TextSymbol).Text = txtText.Text; //FAILING HERE STATING NULL txtText.Text = string.Empty; // spText.Visibility = Visibility.Collapsed; } ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = args.Geometry, Symbol = _activeSymbol, }; graphicsLayer.Graphics.Add(graphic); graphicsLayer.Refresh(); } private void GraphicsLayerG_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs e) { if (EnableEditVerticesScaleRotate.IsChecked.Value) { MyDrawObjectGraphic.DrawMode = DrawMode.None; UnSelectTools(); Editor editor = LayoutRoot.Resources["MyGraphicEditor"] as Editor; if (e.Graphic != null && !(e.Graphic.Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint)) editor.EditVertices.Execute(e.Graphic); } } private void UnSelectTools() { foreach (UIElement element in MyStackPanel.Children) if (element is Button) VisualStateManager.GoToState((element as Button), "UnSelected", false); } private void Tool_Click(object sender, RoutedEventArgs e) { UnSelectTools(); VisualStateManager.GoToState(sender as Button, "Selected", false); switch ((sender as Button).Tag as string) { case "DrawPoint": MyDrawObjectGraphic.DrawMode = DrawMode.Point; _activeSymbol = LayoutRoot.Resources["DefaultGraphicMarkerSymbol"] as Symbol; break; case "DrawPolyline": MyDrawObjectGraphic.DrawMode = DrawMode.Polyline; _activeSymbol = LayoutRoot.Resources["DefaultGraphicLineSymbol"] as Symbol; break; case "DrawPolygon": MyDrawObjectGraphic.DrawMode = DrawMode.Polygon; _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol; break; case "DrawRectangle": MyDrawObjectGraphic.DrawMode = DrawMode.Rectangle; _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol; break; case "DrawFreehand": MyDrawObjectGraphic.DrawMode = DrawMode.Freehand; _activeSymbol = LayoutRoot.Resources["DefaultGraphicLineSymbol"] as Symbol; break; case "DrawArrow": MyDrawObjectGraphic.DrawMode = DrawMode.Arrow; _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol; break; case "DrawTriangle": MyDrawObjectGraphic.DrawMode = DrawMode.Triangle; _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol; break; case "DrawCircle": MyDrawObjectGraphic.DrawMode = DrawMode.Circle; _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol; break; case "DrawEllipse": MyDrawObjectGraphic.DrawMode = DrawMode.Ellipse; _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol; break; case "EnterText": MyDrawObjectGraphic.DrawMode = DrawMode.Point; _activeSymbol = LayoutRoot.Resources["DefaultGraphicMarkerSymbol"] as Symbol; _bolText = true; break; case "DrawNothing": MyDrawObjectGraphic.DrawMode = DrawMode.None; break; default: MyDrawObjectGraphic.DrawMode = DrawMode.None; graphicsLayer.ClearGraphics(); break; } MyDrawObjectGraphic.IsEnabled = (MyDrawObjectGraphic.DrawMode != DrawMode.None); }
Hi Christine,
Before you get into the Switch statement in the Tool_Click routine, reset _bolText to false, otherwise, if the user draws some text and then tries to draw a point/line/ploy afterwards _bolText will still be true it will pass your if _bolText test.
Hope that helps, Terry
case "EnterText": MyDrawObjectGraphic.DrawMode = DrawMode.Point; _activeSymbol = LayoutRoot.Resources["DefaultGraphicMarkerSymbol"] as Symbol; _bolText = true; break;
private void MyDrawObjectGraphic_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args) { if (_bolText) //if user selected text from drawing options { (_activeSymbol as TextSymbol).Text = txtText.Text; txtText.Text = string.Empty; // spText.Visibility = Visibility.Collapsed; } ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = args.Geometry, Symbol = _activeSymbol, }; graphicsLayer.Graphics.Add(graphic); graphicsLayer.Refresh(); }
activeSymbol = new TextSymbol() { Text = "", FontSize = 12, Foreground = new SolidColorBrush(clr), FontFamily = new FontFamily("Arial"), };