Did You Know That… the content property is not the content inside the XAML element?

In a previous Tip of the Day, I talked about using the content property of the Silverlight control (plug-in).

Previous documentation suggested that other XAML objects also have a content property, that is the content within the XAML element, as opposed to the content set specifically as a property.

That erroneous documentation differentiates setting the text in a textblock using the text property

      Canvas.Left ="10"
      Canvas.Top ="50"
      Width ="75"
      Text="Text Property!"/>
from setting the text in the TextBlock as content
   <TextBlock Name="TextBlock2"
      Text Content!

It turns out that the TextBlock  does not have a content member.  Whether set explicitly as a property or as the content of the XAML element, you retrieve the text from the TextBlock using the text property

handleLoad: function(plugIn, userContext, rootElement) 
    this.plugIn = plugIn;
    var tb1 = this.plugIn.content.FindName("TextBlock1");
    var tb2 = this.plugIn.content.FindName("TextBlock2");
    alert("TextBlock1: " + tb1.Text);
    alert("TextBlock2: " + tb2.Text);



kick it on DotNetKicks.com

About Jesse Liberty

Jesse Liberty is the Principal Mobile Developer with IFS Core. He has three decades of experience writing and delivering software projects. He is the author of 2 dozen books and a couple dozen Pluralsight & LinkedIn Learning courses, and has been a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Xamarin Certified Mobile Developer and a Xamarin MVP and a Microsoft MVP.
This entry was posted in z Silverlight Archives and tagged . Bookmark the permalink.