|
using System.Collections.Generic;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media;
namespace SelectionAreaSample
{
public sealed class PolylineGeometryConverter : MarkupExtension, IValueConverter
{
private PathGeometry pathGeometry;
private PathFigure pathFigure;
public PolylineGeometryConverter()
{
pathGeometry = new PathGeometry();
pathFigure = new PathFigure();
pathFigure.IsClosed = true;
pathGeometry.Figures.Add(pathFigure);
}
public override object ProvideValue(System.IServiceProvider serviceProvider)
{
return this;
}
#region IValueConverter Members
public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var p = (Point)value;
if (p.X != double.NegativeInfinity && p.Y != double.NegativeInfinity)
{
var lineSegment = new LineSegment(p, false);
if (pathFigure.Segments.Count == 0)
{
pathFigure.StartPoint = p;
}
pathFigure.Segments.Add(lineSegment);
}
else
{
pathFigure.Segments.Clear();
}
return pathGeometry;
}
public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new System.NotImplementedException();
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.