Hi Paul,

Thanks for the answer, this is exactly what I did, I was just wondering if 
there was a more MicroModelsy solution :)

In the meantime I've another question: why doesn't the MicroModels 
implementation of DelegateCommand use CommandManager.RequerySuggested for its 
implementation of the CanExecuteChanged event? I found that using the current 
implementation doesn't requery the CanExecute delegate when the UI state 
changes (i.e. it's only queried once, when the command is bound, then never 
again).

I changed the implementation of the CanExecuteChanged event to look like so:

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

...and now the CanExecute delegate is requeried whenever the UI state changes 
(e.g. user presses a button).

What do you think about this, is this ok?

Thanks,
Adrian

From: [email protected] [mailto:[email protected]] On 
Behalf Of Paul Stovell
Sent: Tuesday, March 16, 2010 1:35 AM
To: ozWPF
Subject: RE: MicroModels question

Hi Adrian,

I haven't tried, but something like this might work:

private Foo _foo;

public Foo Foo
{
    get { return _foo; }
    set { _foo = value; NotifyChanged("Foo"); }
}

public FooViewModel(Foo foo, Baz baz)
{
     Foo = foo;
     Property(() => Foo.Bar);

     baz.SomeEvent += () => Foo = new Foo();
}

By doing this, the MicroModels expression walker should also subscribe to the 
Foo property change event and re-evaluate when it changes.

Paul



From: [email protected] [mailto:[email protected]] On 
Behalf Of Adrian Hara
Sent: Monday, 15 March 2010 7:16 PM
To: [email protected]
Subject: MicroModels question

Hi,

I'm playing with the very-cool MicroModels framework from Paul Stovell, but I 
have a question. Suppose I have this view model

Class FooViewModel : MicroModel
{
    Public FooViewModel(Foo foo, Baz baz)
    {
         Property(() => foo.Bar);

         baz.SomeEvent += () => foo = new Foo();
    }
}

So the idea is that the underlying domain object upon which the view model is 
based (in this case the instance of Foo) can change (e.g. in response to some 
event). In this case the micro-model properties are "lost", i.e. they are still 
"subscribed" to the old instance of Foo and not to the new one.

What would be a good solution in this case so the properties get re-wired to 
use the new instance of Foo?

Thanks,
Adrian
_______________________________________________
ozwpf mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf

Reply via email to