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 a dictionary in code

Content as a dictionary in code

From the course: Microsoft XAML: 2 Content and Properties

Start my 1-month free trial

Content as a dictionary in code

- [Instructor] Adding items to a resource dictionary is straightforward in code. If you've worked with any other dictionaries in the past, it's very similar to how you work with those. I'll go to the resources property on the window class (keyboard clicking) and it has a method called add. When I add an item, I need to provide a key of type object and the value that I wanna store in their resource dictionary of type object. I'll use strings as the key. (keyboard clicking) As I said, the code is straightforward. The key's a string. The value's instance of a solid color brush is being added the resource dictionary that's part of this resource's property. Copy this line of code, paste it in and add another brush. (keyboard clicking) Since it's typed as object, I can put anything I want in this dictionary. Here's an example of putting a string in the dictionary. (keyboard clicking) I'll use a string for the key (keyboard clicking) and a string for the value. At this point, I've added…

Contents