Answered by:
How to call method that is present in viewmodel from App Resuming event in App.xaml.cs?

Question
-
Hi,
When app comes into app.xaml.cs resuming event ,I need to call method that is present in viewmodel. But viewmodel object is created in xaml(like local:viewmodelclass x:key="vm").Please help me out how to resolve this problem.
Thursday, September 12, 2013 1:13 PM
Answers
-
var viewModel = Application.Current.Resources["vm"] as viewmodelclass;
if(viewModel != null)
{
viewModel.DoSomething();
}
- Marked as answer by Saikrupakar Tuesday, October 15, 2013 9:18 AM
Friday, September 13, 2013 12:48 PM
All replies
-
You can do this in the loaded event which fires when the object model is built.
Jeff Sanders (MSFT)
@jsandersrocks - Windows Store Developer Solutions @WSDevSol
Getting Started With Windows Azure Mobile Services development? Click here
Getting Started With Windows Phone or Store app development? Click here
My Team Blog: Windows Store & Phone Developer Solutions
My Blog: Http Client Protocol Issues (and other fun stuff I support)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, September 13, 2013 12:18 PM
Friday, September 13, 2013 12:18 PMModerator -
var viewModel = Application.Current.Resources["vm"] as viewmodelclass;
if(viewModel != null)
{
viewModel.DoSomething();
}
- Marked as answer by Saikrupakar Tuesday, October 15, 2013 9:18 AM
Friday, September 13, 2013 12:48 PM -
I tried var viewModel = Application.Current.Resources["vm"] as viewmodelclass; but it is throwing COM Exception.
Tuesday, September 17, 2013 6:54 AM -
I tried var viewModel = Application.Current.Resources["vm"] as viewmodelclass; but it is throwing COM Exception.
Hi!
Where you define it? "local:viewmodelclass x:key="vm""
- Edited by Oleg Kurzov Tuesday, September 17, 2013 7:23 AM
Tuesday, September 17, 2013 7:23 AM