xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
xmlns:d='http://schemas.microsoft.com/expression/blend/2008'
xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006'
mc:Ignorable='d'
d:DesignWidth='640' d:DesignHeight='480'>
//File: Page.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication3
{
public partial class MainPage : UserControl
{
Line myLine = new Line();
Point p1 = new Point();
Point p2 = new Point();
Point vectorLength = new Point();
double angle;
public MainPage()
{
InitializeComponent();
p1.X = 0;
p1.Y = 0;
p2.X = 250;
p2.Y = 250;
myLine.X1 = p1.X;
myLine.Y1 = p1.Y;
myLine.X2 = p2.X;
myLine.Y2 = p2.Y;
myLine.StrokeThickness = 1;
SolidColorBrush stroke = new SolidColorBrush();
stroke.Color = Colors.Black;
myLine.Stroke = stroke;
doAngle();
LayoutRoot.Children.Add(myLine);
p1XSlider.Maximum = p2XSlider.Maximum = LayoutRoot.Width;
p1YSlider.Maximum = p2YSlider.Maximum = LayoutRoot.Height;
p1XSlider.Value = myLine.X1;
p1YSlider.Value = myLine.Y1;
p2XSlider.Value = myLine.X2;
p2YSlider.Value = myLine.Y2;
msgP1XSlider.Text = "Point 1 X: " + (Int16)myLine.X1;
msgP1YSlider.Text = "Point 1 Y: " + (Int16)myLine.Y1;
msgP2XSlider.Text = "Point 2 X: " + (Int16)myLine.X2;
msgP2YSlider.Text = "Point 2 Y: " + (Int16)myLine.Y2;
p1XSlider.ValueChanged += new RoutedPropertyChangedEventHandler(p1XSlider_ValueChanged);
p1YSlider.ValueChanged += new RoutedPropertyChangedEventHandler(p1YSlider_ValueChanged);
p2XSlider.ValueChanged += new RoutedPropertyChangedEventHandler(p2XSlider_ValueChanged);
p2YSlider.ValueChanged += new RoutedPropertyChangedEventHandler(p2YSlider_ValueChanged);
}
private void p2YSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
myLine.Y2 = p2YSlider.Value;
msgP2YSlider.Text = "Point 2 Y: " + Convert.ToInt16(p2YSlider.Value);
doAngle();
}
private void p2XSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
myLine.X2 = p2XSlider.Value;
msgP2XSlider.Text = "Point 2 X: " + Convert.ToInt16(p2XSlider.Value);
doAngle();
}
private void p1YSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
myLine.Y1 = p1YSlider.Value;
msgP1YSlider.Text = "Point 1 Y: " + Convert.ToInt16(p1YSlider.Value);
doAngle();
}
private void p1XSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
myLine.X1 = p1XSlider.Value;
msgP1XSlider.Text = "Point 1 X: " + Convert.ToInt16(p1XSlider.Value);
doAngle();
}
private void doAngle()
{
vectorLength.X = myLine.X2 - myLine.X1;
vectorLength.Y = myLine.Y2 - myLine.Y1;
double radians = Math.Atan2(vectorLength.Y, vectorLength.X);
angle = Convert.ToInt16(180 / Math.PI * radians);
testLineAngle.Angle = angle;
msgBlock.Text = "Vector X,Y: " + Convert.ToInt16(vectorLength.X) + ", " + Convert.ToInt16(vectorLength.Y) + "\nAngle: " + angle;
}
}
}