Silverlight authentication during startup - how to mimic syncronous behavior?
I have a Silverlight app that is using the MVVM pattern. I have a WCF service which will allow me to authenticate users (I don't have direct control over that service - assume it is a black box that just returns me the user info and a list of privileges the user has). So, when the app starts up, I want to pull security data from that service.
Right now, when I do this, my views and view models can end up gett开发者_JAVA技巧ing initialized before the service returns with the security data. This causes problems because the view models need to disable buttons and make things visible/invisible based on the user having certain privileges.
Is there a pattern that allows me to prevent the initialization of the views / view models until the WCF call has returned? How would you go about solving this problem as elegantly as possible?
Generally, you use BusyIndicator
from Silverlight Toolkit
for scenarios like this one.
Instead of disabling the UI
, it shows them a progress instead.
What you do is provide a IsBusy
property on ViewModel
. While loading data, set it to True
and False
rest of the time. Wrap your UI
with a BusyIndicator
control and bind that property's value with BusyIndicator
's IsBusy
property.
With this in place, your UI
will acknowledge whenever it's busy.
精彩评论