what the Better way to do master detail with MVVM (catel)

Sep 21, 2011 at 8:49 PM

hi Geert and others :)

I want to make a master - detail scenario with two datagrids or  UserControl 

What are your suggestion to this relationship issue? 

Please  if possible Explain with example

Thanks

Coordinator
Sep 22, 2011 at 5:42 PM

Excellent question. Sorry it took some time to respond, but I decided to write an example application for this including documentation.

The example app is added to the Catel Examples repository, and is called Catel.Examples.WPF.MasterDetail.

The documentation can be found here:

http://catel.catenalogic.com/index.html?creating_a_master_detail_view.htm

Have fun, and if you have any questions, don't hesitate to contact us!

Sep 23, 2011 at 8:05 PM
Edited Sep 23, 2011 at 8:10 PM

tanx for reply

Your solution doesn't solve my problem ,Let me rephrase my question

how to Communicate between two user-controls Or (Two viewmodels )

i have 2 usercontrols , parent and child .

Parent is hosting the child , both have thier own viewmodels .

please see this blog :

http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/1
0/01/10798.aspx

I want to implement this scenario with two usercontorl (Customerview and OrdersView) 
Do you know a better and simple way for implement  this scenario?
maybe I'm wrong here 

I hope you can get what i need, my english is poor, sorry for that. :)

Coordinator
Sep 24, 2011 at 10:00 AM

I think you are looking for the InterestedIn attribute. This way, you can respond to properties and command changes in other view models.

See the documentation for an example. I hope this is what you are looking for.

Sep 24, 2011 at 11:01 AM
Edited Sep 24, 2011 at 11:04 AM

many thanks to you for your great effort :)

nice and easy Method 

   [InterestedIn(typeof(CustomerViewModel))]
    public class CustomerOrdersDetailsViewModel : Catel.MVVM.ViewModelBase
    { ......
     ......
    ......


       protected override void OnViewModelPropertyChanged(IViewModel viewModel, string propertyName)
        {
            if (propertyName == "SelectedCustomer")
            {
                var customerViewModel=   (ViewModel.CustomerViewModel )viewModel;
                var messageService = GetService<IMessageService>();
                var list = (new BusinessLayer.Customers_BS()).GetOrdersbyCustomer(customerViewModel.SelectedCustomer);
                Orders = new ObservableCollection<Model.Order>(list);
                OnPropertyChanged("Orders");
            }
         
        }
      }
Coordinator
Sep 24, 2011 at 11:03 AM

Great that this is what you are looking for :)

One small thing, I recommend this:

if (propertyName == MyViewModelType.SelectedCustomerProperty.Name)

which is much safer in case you go refactoring.

 

Same for OnPropertyChanged, I recommend this:

RaisePropertyChanged(OrdersProperty);

or

RaisePropertyChanged(() => Orders);

Sep 24, 2011 at 11:34 AM

 

okthanks for your advice :)