using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using System.Windows.Shapes; namespace Dominion.NET_WPF.Controls { public sealed class SourceIndicator : UserControl { public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(Point), typeof(SourceIndicator), new FrameworkPropertyMetadata(default(Point))); public Point Source { get { return (Point)GetValue(SourceProperty); } set { SetValue(SourceProperty, value); } } public static readonly DependencyProperty DestinationProperty = DependencyProperty.Register("Destination", typeof(Point), typeof(SourceIndicator), new FrameworkPropertyMetadata(default(Point))); public Point Destination { get { return (Point)GetValue(DestinationProperty); } set { SetValue(DestinationProperty, value); } } public SourceIndicator() { var segment = new LineSegment(default, true); var figure = new PathFigure(default, new[] { segment }, false); var geometry = new PathGeometry(new[] { figure }); BindingBase sourceBinding = new Binding { Source = this, Path = new PropertyPath(SourceProperty) }; BindingBase destinationBinding = new Binding { Source = this, Path = new PropertyPath(DestinationProperty) }; BindingOperations.SetBinding(figure, PathFigure.StartPointProperty, sourceBinding); BindingOperations.SetBinding(segment, LineSegment.PointProperty, destinationBinding); Content = new Path { Data = geometry, StrokeThickness = 5, Stroke = Brushes.MediumSpringGreen, MinWidth = 1, MinHeight = 1 }; } } }