WPF/MVVM: Minimal implementation

Er, why? At work, we have no Windows 10, so the choices are Silverlight, or WPF. WPF then.

As you might expect, comparing this with the previous UWP post, the model and view model parts are identical, precisely because the view model depends on the model, but the view model is not aware of the view implementation (to discuss). So the only thing that needs to change is the view.

Some differences in principle I found (nothing surprising maybe, but worth knowing, for me):

In UWP, I could just drag the XAML and its code-behind under a View folder, and everything would just build. In contrast, in WPF, just dragging caused a build failure, because the StartupUri in App.xaml was not automatically updated to change the relative path. So you need to update that, as shown in the pink underline:

Linking the view to the view model

There are possibly countless ways to do this.. but I only know, or at least can be bothered with, 2.

DataContext in the code-behind, binding referenced in the XAML

No update in the code-behind, XAML handles it all


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s