Child elements of a custom ContentControl cannot be accessed in the code behind - by Dan Rigby

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 785704 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 4/26/2013 12:52:27 PM
Access Restriction Public


Child elements of a custom ContentControl cannot be accessed in the code behind in Windows Store applications.

    <TextBlock x:Name=MyTextBlock" Text=Some Text"/>

(Code Behind)
private void OnPageLoaded(object sender, RoutedEventArgs args) {
  this.MyTextBlock.Text = "New Text"; // Null Reference Exception

I have confirmed this bug exists for both C# and C++ XAML Windows Store applications

I have attached 2 sets of sample code that demonstrate the issue (one in C# and the other in C++).
Set a breakpoint in MainPage.xaml.cs at the end of the MainPage_Loaded event handler and inspect the variable values.

Sign in to post a comment.
Posted by Brian Chapman ex-MSFT on 5/22/2013 at 5:34 PM
This is an issue in the XAML runtime. As you have seen the call to FindName() in the generated code returns null.

The problem is that the CustomContentControl is separate markup and so a separate name scope. That’s why if you remove the constructor (and its call to InitializeComponent) it makes the problem go away.
Posted by Microsoft on 4/28/2013 at 7:50 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 4/26/2013 at 1:51 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(