Victor2748 Victor2748 - 3 months ago 23
C# Question

How to make a WPF button behave like a WinForms Button?

I spent a long time looking for a way to make a boring WPF button be a little more interactive, and behave like a WinForms button, without having to implement that functionality myself. Here is an example of what I want:

Classic WPF button: enter image description here

Windows 10 Winforms button: enter image description here

I even tried using

WindowsFormsHost
to add a WinForms Button to my WPF application like this:

<WindowsFormsHost Grid.Row="0" Grid.Column="0" Width="50" Height="20" HorizontalAlignment="Right" VerticalAlignment="Bottom">
<win:Button Text="Click" Left="50" Top="50" Size="50,20"/>
</WindowsFormsHost>


But it appeared in a gray, old style: enter image description here

How can I add Windows 10 interactivity to my WPF buttons (like in Winforms), without having to implement that functionality myself?

Update:
By "more interactive" I mean to have a thick blue border when in focus, and behave with smooth transitions, like a Windows 10 system button.

Answer

By "more interactive" I mean to have a thick blue border when in focus, and behave with smooth transitions, like a Windows 10 system button.

It's just a matter of styling. Fancy things will require you to override the Template in the style. To do transitions one usually uses the VisualStateManager. (Most controls already have some pre-defined states, so you do not need to invoke VisualStateManager.GoToElementState yourself. The button states along with a usage example style can be found here.)

Comments