From the course: Windows Presentation Foundation 5: Interaction and Controls

Overview

- [Instructor] In this chapter, we'll examine the framework element base class. As you can see from this class diagram, it is the base class for all of the other essential elements that you'll use in your application interface. It implements many useful members that you can use on the controls and other UI elements. Look at the details, over here. For example, there are properties that power the layout system. We'll look in the property section. There's properties like, actual height and actual width. There is a height and a width property. You can change the alignment with horizontal alignment and vertical alignment. You can set, margins. It's part of they layout system. There's a number of properties that deal with maximum and minimum heights and widths. At the framework element level, you find support for data binding which is a powerful technique that automatically shuttles data from a data source to a data target. The data binding properties are the data context and the binding group. Another core feature is down here. It's the style property. This provides a way to group element properties into a style and easily apply that style to many elements. The idea is that you define the style as a resource and then you would assign that resource to the style property. Speaking of resources, they are a way to define a reusable item in your XAML, instead of defining it in your code behind. Resources are created in something called a resource dictionary. The interesting thing as far as this video goes, is that the framework element exposes a resources property of type resource dictionary. That means that any framework element can always store its own resources. There's the parent property. Think about the way we're building our UI. We're building a hierarchy called, tree of elements. That means that most of our elements in your tree have a parent. And so in the framework element class, there's a reference to the parent element here. There's also a triggers property. Triggers are a big topic. One that I'll cover at some point in my WPF series. I won't talk about them in this course. Each framework element can have its own individual cursor. I'll talk about that in this chapter. Each framework element can also have a tool tip. And I'll also talk about that in this chapter. Now, let's go look at some methods. We'll talk about this one. If you define a resource, it has a key. This, find resource, is a way to look through the tree of resource dictionaries and find a resource so that you can use it in code. Same with, find name. If you've named an element, this allows you to walk the tree and find it by name. Now, last we'll take a look at events. There's a couple of events for the context menu. I'll talk about those when I get to the menu chapter. There's an event for the data context changed. That's in case you change the data binding source. There's an event that fires when the size of an element changes. There's also source updated and target updated. These are also events that are affiliated with the data binding engine. And finally, the last two events I want to talk about before I close is, loaded and unloaded. So, let's look at the class details on this. See what it says about loaded. This occurs when the element is laid out, rendered and ready for interaction. So, that means that it's gone through all of those phases. It's gone through being laid out, on the screen. All the pixels are rendered. And it's ready for the user to interact with. And at that point, you can write some code that says, you know, you need to work with that element. The most common place I see using the loaded event is on the window class and on the page class but it's available at the framework element level which means you can write an event handler for any element and say, is this ready? Is it loaded? There's also the opposite, which is the unloaded. When the element is removed from the element tree of loaded elements. So, we've seen that the framework element is one of the essential base classes in WPF. Over 140 elements derive directly, or indirectly, from it. The rest of this chapter looks at examples of its properties and events.

Contents