Posts

Showing posts with the label XAML

WinUI app crashing when you scroll? Here's how to fix it

Years ago, Microsoft introduced this bug in WinUI 2, which can cause WinUI 2 apps to crash then you scroll to the bottom of a scrollable area in a ScrollViewer. You may have noticed this bug in built-in Microsoft apps such as the Microsoft Store, as they use WinUI. This bug was partially addressed in Windows 11, but can still occur.  Luckily, the bug only occurs with WinUI 2 and not plain UWP, so, to fix it, we can just use the UWP ScrollViewer style instead. To do this, just apply a blank style to all or just the offending ScrollViewers like so: <Style TargetType="ScrollViewer"/>  When you create your own style, it inherits from the UWP styles instead of the WinUI 2 styles, as explained here . You could apply it to an individual ScrollViewer like this: <ScrollViewer.Style> <Style TargetType="ScrollViewer"/> </ScrollViewer.Style> Or all of them in App.xaml like so: <Application.Resources> <controls:XamlControlsResources> ...

WPF: How to enable shadows and rounded corners on ToolTips in Windows 11

Image
Windows 11 originally came out in 2021, however, an official Windows 11 theme has not yet been released for WPF (more on that here ). Because of this, WPF apps still have more of a Windows 8/10 look. Luckily, there are some easy things you can do to modernise your WPF user interfaces . You could of course, create your own custom styles, however this can take quite a bit of work. This article covers something that can be done easily, without much work and without breaking compatibility with older operating systems. Enabling shadows and rounded corners on ToolTips WPF presents its ToolTips in seperate top level windows. This allows them to easily show on top of other content and not be limited to the size and position of its parent window. Windows 11 includes a built in feature as part of the DWM (Desktop Window Manager) that rounds top level windows. You can control this feature using the DwnSetWindowAttribute Windows function. Using this function, we can tell Windows 11 to have the DW...

Control no longer using WinUI 2 styles when you apply a custom style to it? Here's how to fix it in XAML

Image
So you've applied your own style to a Button , TextBox , ContentDialog or any other UWP control only to find that the control has reverted to the in-built UWP styles - no longer are WinUI styles being used for the control. Gone are the rounded corners and back are various fluent design lighting effects and 3D button effects common in older versions of Windows 10. You check your custom styles and can't find any reason why the control(s) look like this and you followed the instructions on how to apply the WinUI styles to your app. Well, that's because it's not your fault - this is actually normal behaviour. Read on to see why and the quick and easy fix for it. Why this happens This actually happens due to the default behaviour of UWP. In fact, if you've used WPF (Windows Presentation Foundation), it had the same behaviour. What happens is that whenever you apply your own styles to controls, any properties not defined by the style are inherited by the built-in styles,...

How to show a UAC shield icon in WPF and Windows Forms/WinForms in C# and VB

Image
UAC or User Account Control was introduced in Windows Vista and was a feature that would limit the permissions that processes would have when running under an administrator account. Specifically, processes would have the same permissions as a standard user, even when running under an administrator account, unless the process was elevated - which, by default, would require showing a prompt to the user except for certain Microsoft processes. UAC still exists in Windows today and its behaviour can be customised in Control Panel. A User Account Control prompt in Windows Vista As you've probably seen, controls (such as buttons, links, menu items, etc.) in user interfaces whose default action requires elevation often display a little shield icon next to them. Microsoft recommends doing this in their documentation . UAC shield icons in Windows 11 Control Panel As a WPF (Windows Presentation Foundation) and/or Windows Forms developer, you might want to add this shield icon to your UI to c...