![]() ![]() This allows me to pull some rather cool tricks. The basic layout panel of my window is a grid. The trick to get resizing of the window working is to abuse the grid layout panel. To get this functionality back I needed to write my own resize logic. However it is not resizable, as again windows does no longer provide that functionality. Otherwise the corners will contain black triangles.Īt this point the window is displaying correctly and the window state can be modified. Set AllowTransparency="True" on the window if you are going to create a window with round corners.Otherwise the user clicks 'through' the rectangle. Specify at least Background="Transparent" if you want a rectangle to be clickable to the user.Always set IsTabStop and IsFocusable to false for all parts that are derived from control in the control template of the window.It's just a matter of defining a smaller control.Īs simple as the previous two operations may seem, I still had some minor issues that were preventing my window from working they way I expected it to work. I choose to make it possible to move the window around by grabbing it anywhere in the top region over the full width of the window, but you can of course make it smaller if you like. Now the user can move the window around by just grabbing it at the titlebar. The implementation of this event is again very simple: To emulate this behavior I have added a Control to the titlebar region of my window and hooked up an eventhandler for the MouseDown event. The rest of the buttons is just as simple.Ī normal window can be moved around when you 'grab' it at the titlebar and drag it around. If the user now clicks on the close button, the window will close, piece of cake. Titlebar.MouseDoubleClick += OnTitleBarDoubleClick Titlebar.MouseDown += OnTitleBarMouseDown ![]() In the OnApplyTemplate override I added the following piece of code:īutton minimizeButton = (Button)GetTemplateChild(MinimizeButtonPart) īutton maximizeButton = (Button)GetTemplateChild(MaximizeButtonPart) īutton closeButton = (Button)GetTemplateChild(CloseButtonPart) Ĭontrol titlebar = (Control)GetTemplateChild(TitleBarPart) For now I will only show how I have bound the click event of the close button. You can look the implementation of the chrome buttons up in the source of the photoviewer application. Naming the buttons with x_Name="…" is important because otherwise it's not possible to look them up in the codebehind file. For this I have added the buttons to my control template and named them. Since you can no longer use the minimize, maximize and close button provided by the default win32 implementation of the Window you will need to implement this yourself. For this to work you will need to subclass the Window class from WPF and implement some custom logic. One of the key parts of replacing the window chrome is to not only remove the standard window border, but also emulate every single part of the original window chrome provided by windows. As you can see in the screenshot I made my application to look purple/blueish with round corners. The next step is to define a style and controltemplate for the window, which will define the overall look and feel of the window. After you have done this you end up with just the contents of the window. This is done by setting the border style of the window to none. The first step in creating a custom window chrome is removing the windows chrome. To give you an idea of how it looks when you replace the window chrome I have included a picture of the photoviewer application below: However it is a great example on how you can modify WPF applications in such a way that even the windows look cooler. It is far from finished and the look of the application needs some tweaks to really make it stand out. In this article I will showcase one feature of the photoviewer application, which is the custom window chrome I have been adding the last few days. And a geek has to have something do during his vacation right? There are other applications that might do a better job, but the idea that you have reached your goal of creating a cool WPF application made it well worth the effort. But the main reason for having this application is because I needed some way to manage my photos. This is sort of a way for me to discover what is missing in Composite WPF. The main reason for spending time on this project was to check out the functionality offered in Composite WPF and WPF in general. In my spare time I have been working on a photoviewer application. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |