I'm currently learning WPF. I really am enjoying it so far. I love how easy it is to make great looking apps, and would like to create an app that has a custom window border. I would like for it to look something like this:
I know I could just easily change the Window type to not have a boarder and go from there, but that seems to much like WinForms. Wouldn't it be better to just create a class that derived from Window
and styled it? If so how can I do this? Thanks!
In this article However, you may sometimes want to use Windows Forms controls on your WPF pages. For example, you may have a substantial investment in existing Windows Forms controls, or you may have a Windows Forms control that provides unique functionality.
Click on File >> New >> Project menu and select WPF Application from Templates as shown in Figure 1. In Solution Explorer, right click on References node and select Add Reference menu item. On Browse tab, go to "C:\Program Files\Reference Assemblies\Microsoft\Framework\v3. 0" folder and select WindowsFormsIntegration.
It is based on DirectX with XAML support. It provides access to the native windows library of common controls. It uses markup language for designing UI allowing the design of complex user interfaces.
The most common way to declare a ControlTemplate is as a resource in the Resources section in a XAML file. Because templates are resources, they obey the same scoping rules that apply to all resources.
Here's a great article on customizing Window "chrome" with WPF:
Custom Window Chrome in WPF
It is accompanied by a Code Gallery project from which you can download the code:
WPF Chrome
To show non-standard borders you have to set AllowsTransparency=True and no Border from the window. Whether you want to do this in the class is up to you. You basically have to realize WPF is really just a DirectX application hosted in a standard window. So you if you want non-standard Windows behavior, you have to drop the standard window border and start re-wiring it based on the standard window events you want to handle. Dragging, minimize/maximize/restore, Title bar.
Really, it shouldn't take you more than 30 minutes to an hour to come up with something close to what you want, and you could certainly put your custom window in a base class for re-use on down the road.
I have a feeling, for most cases, this is going to be the better and quicker option than trying override default Windows drawing.
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