This project is read-only.

Mediator communication Views

Jun 29, 2010 at 10:12 AM
Hi, Can the Mediator send messages to Views or just ViewModels?
Jun 29, 2010 at 2:41 PM

as long as you have an IMediator object you can send und register for messages.

Jul 6, 2010 at 8:59 PM

I’m trying to use the Mediator in a multi layered MVVM Silverlight 4 app

I have a view, View Model and a Repository.


On my view I want to show a Busy indicator when the data is being fetched in the Repository.

I have tried to look for an example in the sample demo app but no luck.

The View is bound to the IsBusy Property on the VM but I can’t seem to figure out how to get the MediatorMessageSink wired up.


You think you could maybe extend the sample to add a busy indicator?


Or point me to some example.


I’m sure it’s simple but somehow I not seeing it.


namespace MEFedMVVMDemo.Services.Runtime
    [ExportService(ServiceType.Runtime, typeof(IUsersService))]
    public class UsersService : IUsersService
        #region IUsersService Members

        public IList<Models.User> GetAllUsers()
// This is where a async call is getting data maybe put a timer here that waits 5 seconds This is where I would want to set the busy indicator to busy
            return new List<User>
                new User { Name = "Runtime Marlon", Surname = "Grech", Age = 24 },
                new User { Name = "Runtime Peter", Surname = "O'Hanlon", Age = 35 },
                new User { Name = "Runtime Sasha", Surname = "Barber", Age = 28 },
                new User { Name = "Runtime Glenn", Surname = "Block", Age = 31 },
                new User { Name = "Runtime Josh", Surname = "Smith", Age = 60 },
// we can say where that the data is all there and this is when I would want to set the busy indicator to off



Jul 7, 2010 at 9:22 AM
which sample are you looking at... there is a sample called MEFedMVVMSample that has that
Jul 7, 2010 at 6:29 PM
I have looked at that and have tried to use it, however when Debugging in my app the call to GetCustomers is return a empty collection as the Call is done Async is silverlight. In your sample the Data is right there so works fine. How whould I wire it up if the call is Async? Am I making sense? I am binding my Views to my ViewModels using MEFedMVVM the ViewModels are getting the Data via Async Calls to the Database, as one must do in SL I want to "raise" an event in the Repository Class (You are calling them services, same thing to me) anyway When the Data is done being Fetched I want raise the event in the Repository class called say "DataManagerDone" then on my View I want to "stop the Busy indicator. This is a simple task if I put that logic in the ViewModel as a property and bind my view to it, but I don't want to put it there if at all possiable. I was thinking that the Meditor would work but I can't seam to figure it out. My thought are that I'm making this harder that it sould be. Notice GetCustomers() I'm using DevForce for the Data Junk. If I move this to the ViewModel and Add the IsBusy Property to it, Bind the View to IsBusy works like a champ but I want to move this code to the Repository. //_mgr.Fetching += delegate { IsBusy = true; }; //_mgr.Queried += delegate { IsBusy = false; }; ****************************************** CustomerRepository ****************************************** public void GetCustomers(Action<ObservableCollection<Customer>> customersArrived) { ThreadPool.QueueUserWorkItem(delegate { customersArrived(GetCustomers()); }); } public ObservableCollection<Customer> GetCustomers() { Customers = new ObservableCollection<Customer>(); var query = _mgr.Customers; query.ExecuteAsync(op => op.Results.ForEach(Customers.Add)); //_mgr.Fetching += delegate { IsBusy = true; }; //_mgr.Queried += delegate { IsBusy = false; }; return Customers; } So what you think?
Jul 8, 2010 at 10:14 PM
in the sample MEFedMVVMSample which is in the Samples folder I do get the data Async... are you sure you are looking at the correct sample?