Мне трудно добавить украшений в углы многоугольника . Конечно по углам я представляю в каждой точке локацию.
На этой странице Microsoft описано, как, но мне трудно понять, как использовать их полный пример. Может кто-нибудь, пожалуйста, покажите мне, как адаптироваться?
Большое спасибо.
https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/adorners-overview
// Adorners must subclass the abstract base class Adorner.
public class SimpleCircleAdorner : Adorner
{
// Be sure to call the base class constructor.
public SimpleCircleAdorner(UIElement adornedElement)
: base(adornedElement)
{
}
// A common way to implement an adorner's rendering behavior is to override the OnRender
// method, which is called by the layout system as part of a rendering pass.
protected override void OnRender(DrawingContext drawingContext)
{
Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize);
// Some arbitrary drawing implements.
SolidColorBrush renderBrush = new SolidColorBrush(Colors.Green);
renderBrush.Opacity = 0.2;
Pen renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);
double renderRadius = 5.0;
// Draw a circle at each corner.
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
}
}
Вот мой код, который добавляет полигон к холсту.
Polygon myPolygon;
private Polygon drawPolygon()
{
//Add the Polygon Element
myPolygon = new Polygon();
// Appearance
myPolygon.Stroke = System.Windows.Media.Brushes.LightCoral;
// Disabled for hit testing on border only.
//myPolygon.Fill = System.Windows.Media.Brushes.Transparent;
myPolygon.StrokeThickness = 6;
// Alignment
myPolygon.HorizontalAlignment = HorizontalAlignment.Left;
myPolygon.VerticalAlignment = VerticalAlignment.Center;
// Point Array for polyline.
// This will come from an XML file.
Point[] polylinePoints = {
// START: @ TOP LEFT
new Point(200.0F, 200.0F),
// 1ST LINE: TOP RIGHT
new Point(400.0F, 200.0F),
// 2ND LINE: BOMTTOM RIGHT
new Point(400.0F, 400.0F),
// 3RD LINE: BOTTOM LEFT
new Point(200.0F, 400.0F),
// END: @ TOP LEFT
//Not Required to close the Polygon...
//new Point(200.0F, 200.0F),
};
// Load from Point[Array] polylinePoints.
PointCollection myPointCollection = new PointCollection(polylinePoints);
//myPointCollection.Add(Point1);
// Add from PointCollection myPointCollection
myPolygon.Points = myPointCollection;
return myPolygon;
}