WPF MVVM Authorization
I'm trying to build an authorization mechanism for my WPF/MVVM app. Normally, I can easily place authorization check (ie a call to Authorization service/provider) in the OnStartUp() function of the View's code-behind. To adhere MVVM, however, is there any way to avoid making such a direct call in View, but in ViewModel class instead, so that the View's code-behind remains empty? Or what's the most effective way of implementing auth in WFP/MVVM?
For example, let AuthProvider be a property of the ViewModel, which is bound to the View (as with other properties and commands). How can I proceed that binding in order to implement the authorization mechanism here?
Thank you!
cheers
Create a View for authorization , bind whatever is required in that view to authorization properties in the VM (eg, User name/password UI elements binds to VM.UserName and VM.Password and the Authorize button binds to a Command that authorize the user input and then sets VM.IsAuthorize property if all successful). Upon successful authorization set the VM.IsAuthorized property and bind it to show whatever view under the authorization view or to allow navigation to another view.
This is also a good reading http://blog.magnusmontin.net/2013/03/24/custom-authorization-in-wpf/
链接地址: http://www.djcxy.com/p/9608.html上一篇: 数据映射器和关系:实施策略?
下一篇: WPF MVVM授权