I just read the book on WPF from Thomas Claudius Huber. He stated, that all WPF controls are "lookless". They just get their look (and visual tree) from their ControlTemplate
. That raises one question: Where does the look of WPF come from?
I mean: the Button
has a ControlTemplate
with some Border
s and a ContentPresenter
. Where do these two (Border
and ContentPresenter
) get their look from?
I already googled and found, that Border
is a Decorator
and sets its look in the OnRender
-Method.
Is that the bottom line? Do all other elements which don't have a ControlTemplate define their look in the OnRender
-Method?
The most common way to declare a style is as a resource in the Resources section in a XAML file. Because styles are resources, they obey the same scoping rules that apply to all resources. Put simply, where you declare a style affects where the style can be applied.
Windows Presentation Foundation is a UI framework that creates desktop client applications. The WPF development platform supports a broad set of application development features, including an application model, resources, controls, graphics, layout, data binding, documents, and security. WPF is part of .
With WPF, Microsoft provided much more robust data binding and many more hooks exist that allow the flexibility needed for complicated business applications. You will find yourself using XAML to express the data binding that you would have had to write code for in Windows Forms applications.
Windows Presentation Foundation(WPF) is a development framework used to create a desktop application. It is a part of the . NET framework. The WPF has a resolution-independent and vector-based rendering engine which is helpful to deal with modern graphics hardware.
Short answer: Yes. All visual elements that are not Controls and have a "look", define said look in their UIElement.OnRender
method override.
Long answer: Controls don't use the OnRender
method to define their looks. Instead, their "looks" are defined in Styles and Templates. When no Style or Template is defined explicitly in an application, WPF Controls simply use their default Styles and Templates from the current system Theme (for more info on Themes, check this MSDN article).
Let's just say that the Framework has its own Resource Dictionaries with default Styles for all built-in controls. For instance, here is the default ControlTemplate of the ComboBox: ComboBox Styles and Templates
That being said, there are several visual components that have their looks defined through code, usually through the OnRender
override. They're not Controls; they're Decorators, Shapes and things like that. Things that do have a "look": Border, Rectangle, etc. But in the end, all Controls have look thanks to these elements because all ControlTemplates are made up of either these elements, or other Controls.
TextBlock, as Run, FlowDocument and other similar elements, are special elements created specifically for text renderization. They fall into a similar category than Shapes or Decorators, except they specialize on text rather than graphics. TextBlock, for instance, is not a Control, and defines its look on its OnRender
method. Label, on the other hand, IS a Control; but if you check its Template, you'll see it ends up using a TextBlock to show the text.
There are other elements (like ContentPresenter, ItemsPresenter) that have no look whatsoever, not implicit, not by default, not by Styles or Templates. These are logic elements, that define the structure of the view. ContentPresenter, for instance, grabs the Content
and ContentTemplate
properties of a ContentControl, and makes sure that said Template is correctly rendered and bound to said data, so to speak. But they have no visual representation of their own.
Oh, and I almost forgot about Panels. Panels are not Controls, either, and they do have a look of their own. But similarly to Presenters, they're also logic elements that define how the other visual elements are visualized. More specifically, their layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With