wpf - System.Windows.Shapes.Path incorrect behavior -


after doing research on subject didn't find anything, i'm sorry if same question asked.

task: make colored track-line on canvas after cursor, when left mouse button pressed (like brush in paint).

problem: think using system.windows.shapes.path best approach doing task. code below works fine, except 1 thing: if try move cursor change direction opposite (e.g. value on x-axis increases, decreases, value on y-axis, stays constant), unexpected part of line, corresponding previous direction.

i'm sorry tangled description of problem, hope it.

to make easier reproduce on machine i'm adding solution.

please, point out mistake if did one!

c# using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes;

namespace wpfapplication3 { /// <summary> /// interaction logic mainwindow.xaml /// </summary> public partial class mainwindow : window {     private boolean inserting;     private path path;     private boolean isfirstpoint;      public mainwindow()     {         initializecomponent();         lolcanvas.ishittestvisible = true;     }      private void canvas_mousemove(object sender, mouseeventargs e)     {         if (inserting)         {             point p = mouse.getposition(lolcanvas);             if (isfirstpoint)             {                 pathfigure mypathfigure = new pathfigure();                 mypathfigure.startpoint = new point(p.x + 5, p.y + 5);                 mypathfigure.segments = new pathsegmentcollection();                 (path.data pathgeometry).figures.add(mypathfigure);                 isfirstpoint = false;             }             else             {                 linesegment mylinesegment = new linesegment();                 mylinesegment.point = new point(p.x + 5, p.y + 5);                 (path.data pathgeometry).figures[0].segments.add(mylinesegment);             }         }     }      private void canvas_mousedown(object sender, mousebuttoneventargs e)     {         inserting = true;         path = new path();         path.stroke = new solidcolorbrush(colors.red);         path.strokethickness = 50;         path.data = new pathgeometry();         (path.data pathgeometry).figures = new pathfigurecollection();         lolcanvas.children.add(path);         isfirstpoint = true;     }      private void canvas_mouseup(object sender, mousebuttoneventargs e)     {         inserting = false;     } } } 

xaml:

<window x:class="wpfapplication3.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="mainwindow" height="350" width="525">     <canvas x:name="lolcanvas" mousemove="canvas_mousemove" mousedown="canvas_mousedown"   mouseup="canvas_mouseup" background="black">     </canvas> </window> 

link application: http://ge.tt/99asgyo/v/0?c

apparently kind of behavior correct path. problem appeared because of angle between line parts. 180 degrees, window couldn't render path propertly in place. had 2 ways defeat it: 1) set issmoothjoin property true each line segment. 2) make path object, when kind of problem might occur


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -