I have created a wpf application ,there are two canvas i would like to store controls of both cancas to one collection so that i can process them without two loop. What is the best method to implement this .
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use LINQ’s
Unionoperator to pull the twoCanvas.Childrencollections together into one:Note the following:
The code shown doesn’t actually create a new, mutable collection that you can modify; it merely sets up an
IEnumerable<UIElement>such that you can iterate over both collections’ elements in one go. That is, the two existing collections will be accessed, not a new one.The
Cast<UIElement>operator is necessary becauseCanvas.Childrendoes not implementIEnumerable<T>, but onlyIEnumerable.You need to reference the
System.Core.dllassembly in your project, and import theSystem.Linqnamespace in your code file for this to work.