Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know how to add one Path to a StackPanel, but how can I add a List<Path> to a StackPanel?

What I have tried:

C#
foreach (var onePath in drawThisList)
 {
  myStack.Children.Add(onePath);
 }


But it is not working.
Posted
Updated 28-Apr-19 6:00am
Comments
[no name] 28-Apr-19 9:50am    
Should work. You're obviously missing some "details".
phil.o 28-Apr-19 10:30am    
Please define 'not working'.
Mazin78 28-Apr-19 11:03am    
I get this error {"Specified Visual is already a child of another Visual or the root of a CompositionTarget."}. I traced the foreach loop, and this error happens at the second pass. I don't know how to fix it. Please notice that I am new in programming.
phil.o 28-Apr-19 11:21am    
What is the type of elements in the drawThisList list?
Mazin78 28-Apr-19 14:39pm    
It is:
List<path> drawThisList = new List<path>();

1 solution

 
Share this answer
 
Comments
Mazin78 28-Apr-19 15:04pm    
Thank you Maciej, both the solutions suggest removing previous children before adding a new one. I need to keep the old children and add new ones.
Maciej Los 28-Apr-19 15:11pm    
I think you're still in Windows Forms...
I'd suggest to read these:
How to: Use the WPF Tree Visualizer - Visual Studio | Microsoft Docs[^]
Trees in WPF | Microsoft Docs[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900