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 765283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:51:53+00:00 2026-05-14T16:51:53+00:00

I create a Silverlight Chart, with the Silverlight 4 toolkit, the April release. Consider

  • 0

I create a Silverlight Chart, with the Silverlight 4 toolkit, the April release.

Consider the following chart:

 <Grid x:Name="LayoutRoot" Background="White">
  <Charting:Chart Title="Chart to test" Name="MySuperChart">
   <Charting:LineSeries x:Name="MyLineSeries" Title="Something" />
  </Charting:Chart>
 </Grid>

So far so good. I can access the Series in the chart by MySuperChart.Series[0] But when I try to reference MyLineSeries, it appears to be null.
picture

Full view

  • 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-14T16:51:53+00:00Added an answer on May 14, 2026 at 4:51 pm

    This is an interesting little gotcha. It helps if you look a bit under the hood at how the variable MyLineSeries is created and assigned. Navigate to the definition of the InitializeComponent method. You will end up at the MainPage.g.cs generated file. It will contain this field:-

    internal System.Windows.Controls.DataVisualization.Charting.LineSeries MyLineSeries;
    

    and in the InitializeComponent you will find this line:-

    this.MyLineSeries = ((System.Windows.Controls.DataVisualization.Charting.LineSeries)(this.FindName("MyLineSeries")));
    

    So on the surface of it by the time the call to InitializeComponent in your constructor has completed the MyLineSeries should have been assigned a value. However as you can see its still null, hence it can be concluded that FindName("MyLineSeries") failed to find the series. So the question is why did it fail?

    Why Doesn’t FindName Work?

    FindName searches what is refered to in the documentation as the “object tree”, looking for an object that has the name specified (there are added complications of what are known as namescopes but that is not at play here). Typically objects end up in the “object tree” through common base types like Panel or ContentControl which have propeties such as Children and Child respectively. These properties are specified in the ContentProperty attribute on the classes which allows for the UI structure to be described more naturally. E.g.:-

    <Button x:Name="MyButton">
      <Image x:Name="MyImage" ... />
    </Button>
    

    Instead of

    <Button x:Name="MyButton">
      <Button.Child>
        <Image x:Name="MyImage" ... />
      </Button.Child>
    </Button>
    

    The Chart control, on the other hand, is not a simple Panel derivative and has a lot more work to do to build its UI. In the case of the Chart the ContentPropertyAttribute specifies the Series collection parameter. This allows your more natural Xaml:-

    <Charting:Chart Title="Chart to test" Name="MySuperChart">
      <Charting:LineSeries x:Name="MyLineSeries" Title="Something" />
    </Charting:Chart>
    

    However because Chart has a lot of extra work in order do determine what exactly should be in the “object tree” that will represent its final UI the series collection items don’t immediately become part of the “object tree”. As result the FindName in the InitializeComponent simply doesn’t find them.

    Work Around – Option 1

    You could use your knowledge of the ordinal position of “MyLineSeries” in the chart to handle the assignment of a MyLineSeries variable in the constructor. Remove the x:Name="MyLineSeries" from the Xaml then in code:-

    public partial MainPage : UserControl
    {
      private LineSeries MyLineSeries;
    
      public MainPage()
      {
        InitializeComponent();
        MyLineSeries = (LineSeries)MySuperChart.Series[0];
      }
    }
    

    Work Around – Option 2

    You could wait until the series is available in the “object tree” which is true once the containing UserControl has fired its Loaded event:-

    public partial MainPage : UserControl
    {
      public MainPage()
      {
        InitializeComponent();
        Loaded += (s, args) =>
        {
          MyLineSeries = (LineSeries)FindName("MyLineSeries");
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 380k
  • Answers 380k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As Alex said, asynchronous requests are just that - their… May 14, 2026 at 9:51 pm
  • Editorial Team
    Editorial Team added an answer NSStringFromSelector Conversion in opposite direction is also possible NSSelectorFromString May 14, 2026 at 9:51 pm
  • Editorial Team
    Editorial Team added an answer Try NSString* street = ABRecordCopyValue (record, kABPersonAddressStreetKey); For more information… May 14, 2026 at 9:51 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.