How would I draw something on a Canvas in C# for Windows Phone?
Okay, let me be a little more clear.
Say the user taps his finger down at 386,43 on the canvas. (the canvas is 768 by 480)
I would like my application to be able to respond by placing a red dot at 386,43 on the canvas.
I have no prior experience with Canvas whatsoever.
If this is too complex to be answered in one question (which it probably is), please give me links to other websites with Canvas and Drawing articles.
The primary types of materials used to draw on canvas are graphite pencils, pigment-based colored art pencils, watercolor pencils, soft and oil pastels, and charcoal. Graphite pencils can be used to draw on canvas, but must be sealed with a fixative before they are permanent.
Whether you make your own or you purchase it, transfer paper such as graphite or carbon transfer paper is a great way to transfer a sketch or drawing onto the canvas. The lines it creates tend to hold out a little better on canvas than pencil or charcoal. And a sheet can be used multiple times.
There are various ways of doing this. Depending on the nature of the red dot, you could make it a UserControl. For a basic circle, you can simply handle your canvas' ManipulationStarted
event.
private void myCanvas_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
Ellipse el = new Ellipse();
el.Width = 10;
el.Height = 10;
el.Fill = new SolidColorBrush(Colors.Red);
Canvas.SetLeft(el, e.ManipulationOrigin.X);
Canvas.SetTop(el, e.ManipulationOrigin.Y);
myCanvas.Children.Add(el);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With