How to access App class from any page in Windows phone 8.1 sliverlight application? - silverlight

I have define some properties at application level in windows phone 8.1 sliverlight. Now I want to get an object of app.xaml.cs from any page like we can get application class in android. Please let me know if anyone knows.

If i'm not mistake the App class is static which means that you can call it in your page like this
App.MyProperty
Just make sure you make your properties static
If you have many things you want to access just create a new static class and add everything there, you'll it like I mentioned above

Related

NavigationService.Navigate not working on my Windows Phone Silverlight 8.1

I am trying to invoke this method NavigationService.Navigate
from a class which extends a BaseCommand class (it is a cordova/phonegap plugin) and not a PhoneApplicationPage.
But the framework cannot find it neither Frame
How to achieve it and change the page?
I am using wpsilverlight 8.1
Cordova Windows platform for 8.1 doesn't use Silverlight but uses WWA. So you would need to reference WinRT and WinMD for your scenario. Let us know more about your application and questions you have with our tools. Thanks!

How can I instantiate a page class in windows phone like in desktop Silverlight?

Windows phone template creates MainPage class but I can't see where it instantiates it anywhere in source code ?
So how does it work internally ?
Update: In Silverlight, Instantiation can be done in application startup, what would be the equivalent in Windows Phone ?
The only place I could find it was within the WMAppManifest.xml file. I would assume that the OS uses that to navigate to the MainPage when the app is launched.
<Tasks>
<DefaultTask Name ="_default" NavigationPage="MainPage.xaml"/>
</Tasks>
The PhoneApplicationPage is a control. Yes, when you navigate to the page, object for the Page is internally created. You can, of course, refer to them in their namespaces, as with any other control. Like with any other framework, some things are taken care of, by the framework.

passing value from one page to another

i m new developer to mobile apps and working on silverlight.
i want to knw how to pass value from textbox on one page to textbox on another page in mobile windows apps not in web apps using silverlight in c#.
So many options for this one:
Add variables to your app class
Global variable anywhere in the app (yuk)
Use a shared ViewModel if you are following the MVVM pattern
Store in App.Resource settings (these are easily bound to)
There is a shared app data store specifically for binding, but I can't remember what it is called or if it is in the mobile version (anybody?).
What are you doing with this value that is shared between to pages? The usage determines where/how it should be stored.

How to access web application class into silverlight application

I am beginner in silverlight..I have created a silverlight project. When a new silverlight project is created it is automatically creating a silverlight application and one web application. I have added a class in both applications. Now I want to access a method of web application class into silverlight application class. Is it possible? I have tried to add web application reference to silverlight but VS is not allowing. Is there any another way to do??
What you need is called WCF. A really simple tutorial that should get you going is found here: How to call WCF methods from Silverlight controls
Fundementally WCF allows the silverlight client to make method calls on a class instance hosted on the web site.
Yes it is possible, but not in the normal way. A Silverlight assembly can only reference another Silverlight assembly (this is a limitation of VS2008, i don't know if it has been changed in VS2010).
What you need to do is add an existing file to your Silverlight project, when the file browse dialog opens you navigate to the class file you want to reuse, but instead of just clicking the Add button, click on the little down arrow on the button and choose Add as link - now the file will "exist" in both projects and can be used in both.
If you are going to do this repeatedly though, you will want to move those shared class files out into a separate assembly, do a project reference from your web app, and have the equivalent Silverlight class library mirroring it (sharing the files as links), and then project reference that Silverlight class library from your Silverlight app.

Open a wpf app from a console app and pass objects to it

We would like to open a wpf app from a console app and pass objects which were initialized in the console app to the wpf app. Just wondering if this is possible.
Thanks
N
You could use the command line and pass serialized objects as arguments but this will only work 1 time, when you start the wpf app.
If you need to maintain an ongoing conversation between the two you will need to host a wcf service in the wpf app and talk to it that way.
IMO hosting a service in the WPF app is the best way to go.
You can pass objects in the constructor of your wpf window just like any other class..
Ex: Window1 window = new window1(myObject);

Resources