This tutorial shows how to use C# code to define object data and assign to ContentControls Content property.
- [Instructor] In this video, I'll look at how to set…the content property of a content control in code,…instead of in XAML.…To do that, I'll need to have some content controls…in my stack panel inside my window.XAML file…I've got three buttons,…those are content controls.…I also have a text block, which is not a content control,…but has a tooltip property, which does accept content.…In order to work with these items and the code behind,…they have to have a name.…You see, on line 11,…I'm using the x colon name attribute,…and I assigned the Button2 name to this button element.…
Next, we'll go to the code behind,…and in the constructor,…I'll set the content property of the first button…to a string literal.…Before I type in the equal sign, I'll hover over this…to show you that the type of this property is of object,…which means that an instance of any dot net type…can be assigned here.…It could be a nonvisual class, like this string…I'll be using, or it could be a visual element…like an ellipse or an image.…I got my string literal, I'll assign it to…
- What does content mean in XAML?
- Using dotPeek to show property values for XAML elements
- Expressing content as objects, lists, or dictionaries in XAML vs. code
- Exploring dependency and attached properties
- Working with attached properties in the grid and canvas
- Using custom dependency properties