From the course: Microsoft XAML: 2 Content and Properties

Unlock the full course today

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

Content as a list in code

Content as a list in code

From the course: Microsoft XAML: 2 Content and Properties

Start my 1-month free trial

Content as a list in code

- [Instructor] In this video I'll look at how to add items to this list box in the C Sharp code, not in the XAML. To do that, I need to give my list box a name. I've called this one Tour List Box, and I'll have to set a property in the C Sharp code. Let's review which property is the content property. I've opened up dotPeek. I'm looking at the Items Control class. That's the base class for the list box. And on line 41 over here, you see that the content property is called Items. So I'll switch back to visual studio, open my C Sharp file, go to Items. That tells me that holds an Items collection, and if you know much about collections, you know there's typically a method like Add or Remove. So I'll call Add. And then I need to instantiate the item that I want to add to the list. This could be a simple string. It could be a text block. It can be complicated UI. I'll start by adding a simple string. Next I'll add a text block like that. So I instantiate a text block and I set its text…

Contents