I will also talk about a few key points after that.Ĭopy Code Binding to Templated Parent
Some Triggers are set for IsMouseOver/ IsPressed to change the icon's look,Īnd also for IsChecked to change the icon when the button is toggled. To be the header, which are then laid out using a Grid. Inside the ToggleButton's template, we will use WPF Shapes to draw our icon and another ContentPresenter The first step is to create a ControlTemplate for the ToggleButton ( Expander's button) this will later be used within All of these parts are then laid out using a DockPanel,īut it really could be any layout control of your choice. The ControlTemplate that will be described here uses a templated ToggleButtonįor the header/icon parts, and a ContentPresenter for the actualĮxpander content. For example, "header" means the part in the diagram, while "Header" "header", and "content" for easier reference. Typically, an Expander control is visually composed of three parts. The reader should also be familiar (or willing to lookup) commonly used controls such as Grid, DockPanel, ToggleButton, etc. A basic knowledge of Animations will be very helpful. It is expected that the reader has basic understanding of basic WPF concepts such as Binding and Triggers.
The code shown in this article was designed to be both. Then, a couple more complex versions will be built on top of the default template with customizations such as adding animationĪnd changing the look and feel. Of the default template is explained in detail.
This article will demonstrate how to create a ControlTemplate for the WPF Expander control to customize its appearance and behavior.