Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have dynamically created a label in my WPF Application.Now I want to delete the label from canvas by Name. How can i delete it using LINQ.
Posted

1 solution

LINQ is not used from deletion of UI objects. Please see:
http://en.wikipedia.org/wiki/Language_Integrated_Query[^],
http://msdn.microsoft.com/en-us/library/vstudio/bb397926.aspx[^].

"Delete by Name" does not look accurate. You can search an object by Name (which is probably a pretty bad idea in this case) and remove the found object from the instance of the Canvas. This is a chain of MSDN help pages showing how to do it:
http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.children.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.uielementcollection.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.uielementcollection.remove.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.uielementcollection.removeat.aspx[^].

(Was that clear? OK, this is something like myCanvas.Children.Delete(myUIElement); or myCanvas.Children.DeleteAt(myUIElementIndex). As simple as that.)

—SA
 
Share this answer
 

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