Reflection IT Blog

Benieuwd naar de laatste ontwikkelingen rondom software ontwikkeling en Reflection IT? Onze slimme koppen delen regelmatig hun kennis en ervaring. Zo weet jij wat er speelt!

wpf tagged Blog posts

Using MVVM Design Pattern in Windows Forms

30-Dec-2023 1 Comments

The MVVM Design Pattern is mainly used in XAML enviroments like WPF, UWP, WinUI, Xamarin Forms and MAUI, because they support databinding between Controls and  Models but also between Buttons and Commands.

In .NET 8 it is possible to implement the MVVM Design Pattern in Windows Forms apps. It uses a new data binding engine which was in preview with .NET 7, and is now fully enabled in .NET 8. This new engine is modeled after WPF, which makes it easier to implement MVVM design principles. Time to write a blog post about it.

For this post I have written a simple demo Solution containing 3 projects. The ModelsLibrary project contains a ViewModel and is referenced by a Windows Forms and WPF project. I have published this solution in this GitHub repository

The UI of the Windows Forms and WPF apps are very simple. It shows the value of a Counter and has an Increment button to increment the value by 1. Simular to the Counter sample page of a Blazor app.

Example apps

XAML inline RowDefinitions and ColumnDefinitions

01-Dec-2021 1 Comments

In the XAML of WinUI3 apps you can use the inline syntax for creating Rows and Columns inside a Grid. This is a feature which Avalonia had for a long time. It is more compact and works fine as long as you don't need a Max or Min Width/Height.

The following screenshot shows you a Grid with 2 Rows and Columns. Both in equal size. Using 4 Rectangle elements I created the Microsoft logo inside this Grid.

WinUI XAML with normal Row and Column Definitions

The following screenshot shows you the same Grid but now with inline RowDefinitions and ColumnDefinitions. It saves you a few lines of XAML.

WinUI XAML with inline Row and Column Definitions

XAML CalculatorBehavior

01-Dec-2016

I have been using Adobe software recently and I noticed you could do simple calculations in textboxes. I used it to export Tile Images in different scale sizes. If the 100% scale of an Image is 150 pixels wide you can enter '150 * 1.5'. It will calculate the width of 225 pixels for the 150% scale size. I loved this feature so I tried to implement it also for my own Xaml apps.

The solution is quite simple. I have created a Behavior called CalculatorBehavior. You just use Blend for Visual Studio to drop it on a TextBox control and you are done.

Avalon and ClickOnce demo

23-Sep-2005

I have build my first Windows Presentation Foundation (WPF) application. It is a remake of my WinForms Minesweeper game. Go to the ClickOnce publisher page and install Avalon Minesweeper.

Make sure you have the Microsoft Pre-Release Software WinFX Runtime Components - September Community Technology Preview (CTP) installed on your computer.

To run this sample you must add 'https://www.mydotnetplayground.nl/WpfMinesweeper' to your Trusted Sites in Internet Explorer.

UPDATE 1-1-2006: Moved to my own provider and updated to the December CTP.

Get in touch

Met dit formulier kunt u informatie over een In-Company of Small-Group training aanvragen. U kunt in het bericht aangeven welke training u wilt, voor hoeveel personen, wanneer deze verzorgd moet worden en op welke locatie. Wij nemen vervolgens contact met u op.

U kunt ons ook bereiken via telefoonnummer +31 (0)493-688810 of per mail training@reflectionit.nl.