I have a rather simple case but I can't get the correct solution to it.
On my MVVM application, I would like my MainView
(attached to MainViewModel
) to display current user logon (name) through binding.
User
class is a POCO implementing INPC. The CurrentUser
instance is a static property of my application controller AppController
. The LogOn
property is the string I want to display in MainView
.
So short version : I want to bind AppController.CurrentUser.LogOn
in MainView
.
I tried several ways of static binding (like in this article ), I can't get it to work.
Any idea of out to make this work ?
Thanks.
EDIT:
The problem is that initial binding works, but when I set another User object to current user , the LogOn property is not refreshed, even though AppControl.CurrentUser
property raises a static event PropertyChanged.
EDIT 2
I tried @Henk Holterman solution (echo property from ViewModel) ,and debugging it I found the trick :In fact , the problem was a race condition : my ViewModel was raising the UserChanged event through an EventAggregator , and then raises PropertyChanged , but it was too quick and object reference was not changed on AppController when event raises.
Thank you very much all for your help !