void drawtool_DrawComplete(object sender, DrawEventArgs e)
        {
            e.Geometry.SpatialReference = MyMap.SpatialReference;
            Graphic graphic = new Graphic()
            {
                Geometry = e.Geometry
            };

            if (e.Geometry is MapPoint)
            {
                graphic.Symbol = LayoutRoot.Resources["DrawPointSymbol"] as SimpleMarkerSymbol;
            }
            else if (e.Geometry is Polyline)
            {
                graphic.Symbol = LayoutRoot.Resources["DrawPolylineSymbol"] as SimpleLineSymbol;
            }
            else if (e.Geometry is Polygon || e.Geometry is Envelope)
            {
                graphic.Symbol = LayoutRoot.Resources["DrawPolygonSymbol"] as SimpleFillSymbol;
            }

            drawGraphicsLayer.Graphics.Add(graphic);
            draw.IsEnabled = false;

            Geometry fromGeometry = null;
            Geometry toGeometry   = null;

            switch (mensurationOperation)
            {
            case MensurationOperation.DistanceAndAngle:
            case MensurationOperation.HeightFromBaseAndTop:
            case MensurationOperation.HeightFromBaseAndTopShadow:
            case MensurationOperation.HeightFromTopAndTopShadow:
                fromGeometry = (e.Geometry as Polyline).Paths[0][0];
                fromGeometry.SpatialReference = MyMap.SpatialReference;
                toGeometry = (e.Geometry as Polyline).Paths[0][1];
                toGeometry.SpatialReference = MyMap.SpatialReference;
                break;

            case MensurationOperation.AreaAndPerimeter:
            case MensurationOperation.Centroid:
            case MensurationOperation.Point:
                fromGeometry = e.Geometry;
                break;
            }

            esriUnits?LinearUnit = null;

            switch (comboLinearUnit.SelectedIndex)
            {
            case 0:
                LinearUnit = esriUnits.esriUnknownUnits;
                break;

            case 1:
                LinearUnit = esriUnits.esriInches;
                break;

            case 2:
                LinearUnit = esriUnits.esriPoints;
                break;

            case 3:
                LinearUnit = esriUnits.esriFeet;
                break;

            case 4:
                LinearUnit = esriUnits.esriYards;
                break;

            case 5:
                LinearUnit = esriUnits.esriMiles;
                break;

            case 6:
                LinearUnit = esriUnits.esriNauticalMiles;
                break;

            case 7:
                LinearUnit = esriUnits.esriMillimeters;
                break;

            case 8:
                LinearUnit = esriUnits.esriCentimeters;
                break;

            case 9:
                LinearUnit = esriUnits.esriMeters;
                break;

            case 10:
                LinearUnit = esriUnits.esriKilometers;
                break;

            case 11:
                LinearUnit = esriUnits.esriDecimalDegrees;
                break;

            case 12:
                LinearUnit = esriUnits.esriDecimeters;
                break;
            }

            DirectionUnit AngularUnit = DirectionUnit.Default;

            switch (comboAngularUnit.SelectedIndex)
            {
            case 0:
                AngularUnit = DirectionUnit.Default;
                break;

            case 1:
                AngularUnit = DirectionUnit.Radians;
                break;

            case 2:
                AngularUnit = DirectionUnit.DecimalDegrees;
                break;

            case 3:
                AngularUnit = DirectionUnit.DegreesMinutesSeconds;
                break;

            case 4:
                AngularUnit = DirectionUnit.Gradians;
                break;

            case 5:
                AngularUnit = DirectionUnit.Gons;
                break;
            }

            AreaUnit AreaUnits = AreaUnit.Default;

            switch (comboAreaUnit.SelectedIndex)
            {
            case 0:
                AreaUnits = AreaUnit.Default;
                break;

            case 1:
                AreaUnits = AreaUnit.SquareInches;
                break;

            case 2:
                AreaUnits = AreaUnit.SquareFeet;
                break;

            case 3:
                AreaUnits = AreaUnit.SquareYards;
                break;

            case 4:
                AreaUnits = AreaUnit.Acres;
                break;

            case 5:
                AreaUnits = AreaUnit.SquareMiles;
                break;

            case 6:
                AreaUnits = AreaUnit.SquareMillimeters;
                break;

            case 7:
                AreaUnits = AreaUnit.SquareCentimeters;
                break;

            case 8:
                AreaUnits = AreaUnit.SquareDecimeters;
                break;

            case 9:
                AreaUnits = AreaUnit.SquareMeters;
                break;

            case 10:
                AreaUnits = AreaUnit.Ares;
                break;

            case 11:
                AreaUnits = AreaUnit.Hectares;
                break;

            case 12:
                AreaUnits = AreaUnit.SquareKilometers;
                break;
            }

            if (!mensurationTask.IsBusy)
            {
                switch (mensurationOperation)
                {
                case MensurationOperation.AreaAndPerimeter:
                    MensurationAreaParameter p1 = new MensurationAreaParameter();
                    p1.LinearUnit = LinearUnit;
                    p1.AreaUnits  = AreaUnits;
                    mensurationTask.AreaAndPerimeterAsync(fromGeometry as Polygon, p1);
                    break;

                case MensurationOperation.Centroid:
                    MensurationPointParameter p3 = new MensurationPointParameter();
                    mensurationTask.CentroidAsync(fromGeometry as Polygon, p3);
                    break;

                case MensurationOperation.DistanceAndAngle:
                    MensurationLengthParameter p5 = new MensurationLengthParameter();
                    p5.LinearUnit  = LinearUnit;
                    p5.AngularUnit = AngularUnit;
                    mensurationTask.DistanceAndAngleAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p5);
                    break;

                case MensurationOperation.Point:
                    MensurationPointParameter p7 = new MensurationPointParameter();
                    mensurationTask.PointAsync(fromGeometry as MapPoint, p7);
                    break;

                case MensurationOperation.HeightFromBaseAndTop:
                    MensurationHeightParameter p9 = new MensurationHeightParameter();
                    p9.LinearUnit = LinearUnit;
                    mensurationTask.HeightFromBaseAndTopAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p9);
                    break;

                case MensurationOperation.HeightFromBaseAndTopShadow:
                    MensurationHeightParameter p10 = new MensurationHeightParameter();
                    p10.LinearUnit = LinearUnit;
                    mensurationTask.HeightFromBaseAndTopShadowAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p10);
                    break;

                case MensurationOperation.HeightFromTopAndTopShadow:
                    MensurationHeightParameter p11 = new MensurationHeightParameter();
                    p11.LinearUnit = LinearUnit;
                    mensurationTask.HeightFromTopAndTopShadowAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p11);
                    break;
                }
            }
        }
        void drawtool_DrawComplete(object sender, DrawEventArgs e)
        {
            e.Geometry.SpatialReference = MyMap.SpatialReference;
            Graphic graphic = new Graphic() { Geometry = e.Geometry };

            if (e.Geometry is MapPoint)
                graphic.Symbol = LayoutRoot.Resources["DrawPointSymbol"] as SimpleMarkerSymbol;
            else if (e.Geometry is Polyline)
                graphic.Symbol = LayoutRoot.Resources["DrawPolylineSymbol"] as SimpleLineSymbol;
            else if (e.Geometry is Polygon || e.Geometry is Envelope)
                graphic.Symbol = LayoutRoot.Resources["DrawPolygonSymbol"] as SimpleFillSymbol;

            drawGraphicsLayer.Graphics.Add(graphic);
            draw.IsEnabled = false;

            Geometry fromGeometry = null;
            Geometry toGeometry = null;
            switch (mensurationOperation)
            {
                case MensurationOperation.DistanceAndAngle:
                case MensurationOperation.HeightFromBaseAndTop:
                case MensurationOperation.HeightFromBaseAndTopShadow:
                case MensurationOperation.HeightFromTopAndTopShadow:
                    fromGeometry = (e.Geometry as Polyline).Paths[0][0];
                    fromGeometry.SpatialReference = MyMap.SpatialReference;
                    toGeometry = (e.Geometry as Polyline).Paths[0][1];
                    toGeometry.SpatialReference = MyMap.SpatialReference;
                    break;
                case MensurationOperation.AreaAndPerimeter:
                case MensurationOperation.Centroid:
                case MensurationOperation.Point:
                    fromGeometry = e.Geometry;
                    break;
            }

            esriUnits? LinearUnit = null;
            switch (comboLinearUnit.SelectedIndex)
            {
                case 0:
                    LinearUnit = esriUnits.esriUnknownUnits;
                    break;
                case 1:
                    LinearUnit = esriUnits.esriInches;
                    break;
                case 2:
                    LinearUnit = esriUnits.esriPoints;
                    break;
                case 3:
                    LinearUnit = esriUnits.esriFeet;
                    break;
                case 4:
                    LinearUnit = esriUnits.esriYards;
                    break;
                case 5:
                    LinearUnit = esriUnits.esriMiles;
                    break;
                case 6:
                    LinearUnit = esriUnits.esriNauticalMiles;
                    break;
                case 7:
                    LinearUnit = esriUnits.esriMillimeters;
                    break;
                case 8:
                    LinearUnit = esriUnits.esriCentimeters;
                    break;
                case 9:
                    LinearUnit = esriUnits.esriMeters;
                    break;
                case 10:
                    LinearUnit = esriUnits.esriKilometers;
                    break;
                case 11:
                    LinearUnit = esriUnits.esriDecimalDegrees;
                    break;
                case 12:
                    LinearUnit = esriUnits.esriDecimeters;
                    break;
            }

            DirectionUnit AngularUnit = DirectionUnit.Default;
            switch (comboAngularUnit.SelectedIndex)
            {
                case 0:
                    AngularUnit = DirectionUnit.Default;
                    break;
                case 1:
                    AngularUnit = DirectionUnit.Radians;
                    break;
                case 2:
                    AngularUnit = DirectionUnit.DecimalDegrees;
                    break;
                case 3:
                    AngularUnit = DirectionUnit.DegreesMinutesSeconds;
                    break;
                case 4:
                    AngularUnit = DirectionUnit.Gradians;
                    break;
                case 5:
                    AngularUnit = DirectionUnit.Gons;
                    break;
            }

            AreaUnit AreaUnits = AreaUnit.Default;
            switch (comboAreaUnit.SelectedIndex)
            {
                case 0:
                    AreaUnits = AreaUnit.Default;
                    break;
                case 1:
                    AreaUnits = AreaUnit.SquareInches;
                    break;
                case 2:
                    AreaUnits = AreaUnit.SquareFeet;
                    break;
                case 3:
                    AreaUnits = AreaUnit.SquareYards;
                    break;
                case 4:
                    AreaUnits = AreaUnit.Acres;
                    break;
                case 5:
                    AreaUnits = AreaUnit.SquareMiles;
                    break;
                case 6:
                    AreaUnits = AreaUnit.SquareMillimeters;
                    break;
                case 7:
                    AreaUnits = AreaUnit.SquareCentimeters;
                    break;
                case 8:
                    AreaUnits = AreaUnit.SquareDecimeters;
                    break;
                case 9:
                    AreaUnits = AreaUnit.SquareMeters;
                    break;
                case 10:
                    AreaUnits = AreaUnit.Ares;
                    break;
                case 11:
                    AreaUnits = AreaUnit.Hectares;
                    break;
                case 12:
                    AreaUnits = AreaUnit.SquareKilometers;
                    break;
            }

            if (!mensurationTask.IsBusy)
            {
                switch (mensurationOperation)
                {
                    case MensurationOperation.AreaAndPerimeter:
                        MensurationAreaParameter p1 = new MensurationAreaParameter();
                        p1.LinearUnit = LinearUnit;
                        p1.AreaUnits = AreaUnits;
                        mensurationTask.AreaAndPerimeterAsync(fromGeometry as Polygon, p1);
                        break;
                    case MensurationOperation.Centroid:
                        MensurationPointParameter p3 = new MensurationPointParameter();
                        mensurationTask.CentroidAsync(fromGeometry as Polygon, p3);
                        break;
                    case MensurationOperation.DistanceAndAngle:
                        MensurationLengthParameter p5 = new MensurationLengthParameter();
                        p5.LinearUnit = LinearUnit;
                        p5.AngularUnit = AngularUnit;
                        mensurationTask.DistanceAndAngleAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p5);
                        break;
                    case MensurationOperation.Point:
                        MensurationPointParameter p7 = new MensurationPointParameter();
                        mensurationTask.PointAsync(fromGeometry as MapPoint, p7);
                        break;
                    case MensurationOperation.HeightFromBaseAndTop:
                        MensurationHeightParameter p9 = new MensurationHeightParameter();
                        p9.LinearUnit = LinearUnit;
                        mensurationTask.HeightFromBaseAndTopAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p9);
                        break;
                    case MensurationOperation.HeightFromBaseAndTopShadow:
                        MensurationHeightParameter p10 = new MensurationHeightParameter();
                        p10.LinearUnit = LinearUnit;
                        mensurationTask.HeightFromBaseAndTopShadowAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p10);
                        break;
                    case MensurationOperation.HeightFromTopAndTopShadow:
                        MensurationHeightParameter p11 = new MensurationHeightParameter();
                        p11.LinearUnit = LinearUnit;
                        mensurationTask.HeightFromTopAndTopShadowAsync(fromGeometry as MapPoint, toGeometry as MapPoint, p11);
                        break;
                }
            }
        }