Posts

Showing posts from February, 2023

How to change the colour of a WPF or Windows Forms/WinForms title bar in Windows 11 in C# and VB

Image
The windows title bar has gone through various changes throughout the years - from the old title bars with user customisable colours to the newer title bars with visual styling support introduced in Windows XP to the DWM (Desktop Window Manager) rendered title bars introduced in Windows Vista. One thing about these changes is that they often explored the concepts the relationship of the title bar to the client area of Windows and who is in control of what the title bar looks like. For example, in Windows XP, the user could only choose between specific title bar styles unless you used the Windows classic theme, in which case you could choose your own title bar colours or even use gradients if you wanted. With the addition of the DWM in Windows Vista, Microsoft explored the idea of extending the title bar into the non client area of Windows - think File Explorer and Microsoft Word for example. Where we are now In modern versions of Windows, the title bar only uses the DWM version and all

Can't scroll with touch in your WPF app? Make sure to set the correct PanningMode!

So you have some content in a WPF (Windows Presentation Foundation) UI that might not always fit in its parent and so you put it in a ScrollViewer . You then try to scroll it using the panning gesture on a touch screen, only to find that the content doesn't scroll. Don't worry, it's not that WPF doesn't support scrolling with the pan gesture on a touch screen - you just have to enable it! How to enable touch panning on a ScrollViewer to scroll in WPF To enable using the touch screen pan gesture to scroll a ScrollViewer 's contents, just use the PanningMode. Here's how to do it in XAML : < ScrollViewer PanningMode ="Both"> C# : ScrollViewer.PanningMode = PanningMode.Both; And VB : ScrollViewer.PanningMode = PanningMode.Both Make sure to replace 'ScrollViewer' in the above C# and VB code with the name of the ScrollViewer you want to affect! The above examples enable panning in all directions when you perform the touch screen panning gestur

Make your TextBoxes easier to scroll: How to enable horizontal and vertical scrollbars in a WPF TextBox in XAML, C# and VB

Image
WPF's (Windows Presentation Foundation's) TextBox control is one of its most fundamental and useful controls - you can use it for anything from requesting small amounts of text from the user to huge chunks of text with multiple lines. It even supports spell check as well. Now, one of the issues you might find, however, when using a TextBox for accepting large amounts of text is that it might be hard for the user to scroll through the text in a TextBox. By default, the only ways to scroll a WPF TextBox are a) to move the text cursor and the TextBox will scroll automatically to the location of the cursor, b) to scroll vertically with a scrollwheel or touchpad gesture (More info on that here ) or c) to scroll with a touch screen using the panning gesture (through to scroll horizontally you must first start scrolling vertically). As you can tell, these options are limited - moving the text cursor to scroll is a slow and cumbersome process and with a scroll wheel or touchpad you can