Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Won't Fix Help for as Won't Fix


1
0
Sign in
to vote
Type: Bug
ID: 785704
Opened: 4/26/2013 12:52:27 PM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description



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

Example:
<Grid>
<local:MyCustomContentControl>
    <TextBlock x:Name=MyTextBlock" Text=Some Text"/>
</local:MyCustomContentControl>
</Grid>

(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.

Thanks.
Details
Sign in to post a comment.
Posted by Brian Chapman _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(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
BugReport.CustomContentControlTemplateCpp.zip 4/26/2013 26 KB
BugReport.CustomContentControlTemplate.zip 4/26/2013 23 KB