Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4126162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:57:53+00:00 2026-05-20T23:57:53+00:00

I try to add two Canvas to a List<Canvas> , but I receive exception

  • 0

I try to add two Canvas to a List<Canvas>, but I receive exception from the following code:

List<Canvas> cvList = new List<Canvas>();

Canvas cv = new Canvas();
cv.Width = 100; 
cv.Height = 100;

cvList.Add(cv); // adding first Canvas to List<Canvas>
cvList.Add(cv); // adding the second Canvas to List<Canvas>
...

To elaborate more on the issue, each Canvas has to be distinct since each may Children different TextBox, Label and other UIElement. So I think the above code shouldn’t work. However though I cannot do this:

Canvas cv1 = new Canvas();
cv1.Width = 100;
Canvas cv2 = new Canvas();
cv2.Width = 250;
...

Or 

Canvas[] cv = new Canvas[myInt];

I cannot do the above because the size of the List is determine at run time and I cannot assign a size to an Array or declare each array individually.

How to do this correctly? Yes, I’ve read the List on MSDN, but the site didn’t tell me how to do so. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:57:53+00:00Added an answer on May 20, 2026 at 11:57 pm

    To elaborate on Joels answer, this is what you need to do:

    List<Canvas> cvList = new List<Canvas>();
    
    Canvas canvas1 = new Canvas();
    canvas1.Width = 100; 
    canvas1.Height = 100;
    cvList.Add(canvas1);
    
    Canvas canvas2 = new Canvas();
    canvas2.Width = 100; 
    canvas2.Height = 100;
    cvList.Add(canvas2);
    

    Note that adding the same element twice to the same List<Canvas> collection in this way is perfectly legal, however attempting to use the same element twice in a layout (as might happen depending on the way that this list is used) is not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i try to add two numbers received from a file. But it shows only
try the following: add two divs to a page with the same class name.
I've tried the add() method but nothing is displayed when I try to add
I've successfully merged 3 tables (using ID's), but when I try to add 4th
I have the following two functions which take two dictionaries and recursively add their
I try to add object to my NSMutable array in my method, but keep
I try to add dots between the page title and the page number in
I try to add Message.framework to my project frameworks directory. After that I compile
I try to add a class to a td-element using javascript with the internet
I try to add a class to a link with jquery <a rel=/Career/ href=/Career/></a>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.