WPF: Drawing a line on MouseMove purely in XAML

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.

Answers


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

<InkCanvas />

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


Need Your Help

What's the BPF for HTTP?

c packet-capture

The definition can be seen here.

I'm creating menubar

html css menuitem

I'm creating a menu bar using HTML and CSS, I want to put a centered border around the menu text