From the course: Microsoft XAML: 2 Content and Properties

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Content as an object in code

Content as an object in code

From the course: Microsoft XAML: 2 Content and Properties

Start my 1-month free trial

Content as an object in code

- [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…

Contents