Skip to content

Instantly share code, notes, and snippets.

@vquaiato
Created February 17, 2011 20:37
Show Gist options
  • Save vquaiato/832626 to your computer and use it in GitHub Desktop.
Save vquaiato/832626 to your computer and use it in GitHub Desktop.
Very simples canvas dashboard in WPF
public partial class MainWindow : Window
{
private Line line = null;
private Brush oldBrush;
public MainWindow()
{
InitializeComponent();
}
void onDragDelta(object sender, DragDeltaEventArgs e)
{
line = new Line { Stroke = Brushes.Black, StrokeThickness = 1 };
var element = sender as Thumb;
line.X1 = Canvas.GetLeft(element);
line.X2 = line.X1 + e.HorizontalChange;
Canvas.SetLeft(element, Canvas.GetLeft(element) +
e.HorizontalChange);
line.Y1 = Canvas.GetTop(element) + 15;
line.Y2 = line.Y1 + e.VerticalChange;
Canvas.SetTop(element, Canvas.GetTop(element) +
e.VerticalChange);
this.myCanvasStretch.Children.Add(line);
}
void onDragStarted(object sender, DragStartedEventArgs e)
{
var element = sender as Thumb;
oldBrush = element.Background;
element.Background = Brushes.DarkGray;
}
void onDragCompleted(object sender, DragCompletedEventArgs e)
{
line = null;
var element = sender as Thumb;
element.Background = oldBrush;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment