Silverlight – Run Time Exception – Value does not fall within the expected range

If you are getting this error, you need to make sure that all xaml elements have unique names.
Consider the following code snippets-

for (int Count = 0; Count < StackPanel.Children.Count; Count++)
{
   Chart ch = (Chart)StackPanel.Children[Count];
   AnotherStackPanel.Children.Add(ch);
}

The line AnotherStackPanel.Children.Add(ch); may lead to the same error. To remove this, change name of Chart xaml element so that all element has unique name. Example-

for (int Count = 0; Count < StackPanel.Children.Count; Count++)
{
   Chart ch = (Chart)StackPanel.Children[Count];
   //changing name of chart so that each chart has unique name
   ch.Name = ch.Name + "ChangedName" + Convert.ToString(Count);
   AnotherStackPanel.Children.Add(ch);
}
This entry was posted in Knowledge Sharing, Silverlight, Troubleshooting. Bookmark the permalink.

2 Responses to Silverlight – Run Time Exception – Value does not fall within the expected range

  1. LenHewitt says:

    Hello, this is my first time i visit here. I found so many interesting in your blog especially on how to determine the topic. keep up the good work.

  2. Useful details, a number of thanks to the author. It is puzzling to me now, but in general, the usefulness and importance is overwhelming. Quite a lot thanks again and superior luck!

Leave a Reply