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
From the course: Microsoft XAML: 2 Content and Properties
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
What does content mean in XAML?3m 41s
-
Use children elements as content7m 5s
-
Install the dotPeek utility1m 16s
-
How each element defines a content property5m 28s
-
Content as an object in XAML6m 32s
-
Content as an object in code5m 33s
-
Visual content in panels4m 59s
-
Content as a list in XAML3m 53s
-
Content as a list in code3m 6s
-
Content as a dictionary in XAML4m 53s
-
Content as a dictionary in code1m 25s
-
-
-