Question

I am new to WPF and I was wondering if I could draw a line that updated with mouse position purely in XAML?

I know I can do:

...
<Canvas x:Name="MyCanvas">
   <Polyline x:Name="MyLine" Points="0,0 1,1" Stroke=1 />
</Canvas>
...

Than in C#

private void MyCanvas_MouseMove(...)
{
   if(!DrawFlag)
       return;

   Point Pos = new Point();
   Pos = e.GetPosition(MyCanvas);
   MyLine.Points[ MyLine.Points.Count - 1 ] = Pos;
}

Is there a way to have a flag set, DrawFlag, and then have the point position update using only XAML code? I get a feeling the answer may be in creating a Template but not really sure.

Was it helpful?

Solution

It is possible to draw on a canvas purely with XAML using an InkCanvas

<InkCanvas />

OTHER TIPS

No, you can't do that purely in XAML. XAML is a presentation language, not a "real" programming language.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top