drawing in ui_canvas

Hi.
I use ui_canvas. In it I draw line that will change the position.
 Line myLine = new Line();
            myLine.Stroke = System.Windows.Media.Brushes.LightSteelBlue;
            myLine.X1 = 0;
            myLine.X2 =100;
            myLine.Y1 = CurHor;
            myLine.Y2 = CurHor;
            myLine.HorizontalAlignment = HorizontalAlignment.Left;
            myLine.VerticalAlignment = VerticalAlignment.Center;
            myLine.StrokeThickness = 2;
            ui_canvas.Children.Add(myLine);
            myLine = null;
But I cannot refresh view and all lines that was drawing for another values of CurHor are in the ui_canvas. Please see the attached picture.
What can I do to show only the line in current position?
Capture.PNG
LVL 1
mastiSoftAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi mastiSoft;

Have you tried to clear the Children collection before adding the new Line? This can be done by using, ui_canvas.Children.Clear();
0
mastiSoftAuthor Commented:
Hi Fernando.
The line I try to redraw is not alone in the ui_canvas ( It is a horizontal cursor , on this control I also draw data.
             ui_canvas.Children.Clear();
            Data(t_path, V);// here creates the pathGeometry from some data file where t_path path to the file and V position in the file
            ui_path.Data = pathGeometry; // data representation as some curve draws in ui_canvas control
            Line myLine = new Line(); // and here I start to create the cursor (horizontal line)

  If I use  ui_canvas.Children.Clear() as you suggested the data (curve) disappears and I see only the horizontal line that redraws.
0
Fernando SotoRetiredCommented:
Hi mastiSoft;

Sorry about that I misunderstood the question. The ui_canvas.Children is a collection of UIElement's and so if you wish to redraw the line you first need to delete the line you wish to replace and then add the updated line. This may not be that easy. First you need to have a reference to the drawing object you wish to delete and use that reference like this,  ui_canvas.Children.Remove(myLine); myLine is from your original post. Then add your updated line. Now you may want to re-think how you add UIElement's to the collection. For example if you draw the first line then you can insert it in to the collection like this, ui_canvas.Children.Insert(0, myLine);, which will add the myLine to index zero and the second line to index 1 and so on. Please see the MS Documentation for UIElementCollection Class and the methods such as Insert, Remove, RemoveAt and others.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mastiSoftAuthor Commented:
thank you very much )
0
Fernando SotoRetiredCommented:
Not a problem mastiSoft, glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WPF

From novice to tech pro — start learning today.