How should the ViewModel close the form?

I was inspired by Thejuan’s answer to write a simpler attached property. No styles, no triggers; instead, you can just do this: <Window … xmlns:xc=”clr-namespace:ExCastle.Wpf” xc:DialogCloser.DialogResult=”{Binding DialogResult}”> This is almost as clean as if the WPF team had gotten it right and made DialogResult a dependency property in the first place. Just put a bool? … Read more

Binding a WPF ComboBox to a custom list

You set the DisplayMemberPath and the SelectedValuePath to “Name”, so I assume that you have a class PhoneBookEntry with a public property Name. Have you set the DataContext to your ConnectionViewModel object? I copied you code and made some minor modifications, and it seems to work fine. I can set the viewmodels PhoneBookEnty property and … Read more

Data binding to SelectedItem in a WPF Treeview

I realise this has already had an answer accepted, but I put this together to solve the problem. It uses a similar idea to Delta’s solution, but without the need to subclass the TreeView: public class BindableSelectedItemBehavior : Behavior<TreeView> { #region SelectedItem Property public object SelectedItem { get { return (object)GetValue(SelectedItemProperty); } set { SetValue(SelectedItemProperty, … Read more

WPF MVVM navigate views

Firstly, you don’t need any of those toolkits/frameworks to implement MVVM. It can be as simple as this… let’s assume that we have a MainViewModel, and PersonViewModel and a CompanyViewModel, each with their own related view and each extending an abstract base class BaseViewModel. In BaseViewModel, we can add common properties and/or ICommand instances and … Read more

Good or bad practice for Dialogs in wpf with MVVM?

This is a good approach and I used similar ones in the past. Go for it! One minor thing I’d definitely do is make the event receive a boolean for when you need to set “false” in the DialogResult. event EventHandler<RequestCloseEventArgs> RequestCloseDialog; and the EventArgs class: public class RequestCloseEventArgs : EventArgs { public RequestCloseEventArgs(bool dialogResult) … Read more

MVVM: Tutorial from start to finish?

Your question really seems to be asking 2 questions: Where are some good tutorials on WPF, assuming I have no previous WPF experience? Where are some good tutorials on learning MVVM? Some of these resources may be duplicated in previous answers… Tutorials on WPF A Guided Tour of WPF by Josh Smith I wrote a … Read more