App. CS
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. net;
Using system. windows;
Using system. Windows. controls;
Using system. Windows. documents;
Using system. Windows. input;
Using system. Windows. Media;
Using system. Windows. Media. animation;
Using system. Windows. Media. imaging;
Using system. Windows. Navigation;
Using system. Windows. shapes;
Using Microsoft. Phone. controls;
Using Microsoft. Phone. shell;
Namespace photoapp
{
Public class globaldata
{
Public bitmapimage;
}
Public partial class app: Application
{
Public static globaldata;
/// <Summary>
/// Provides easy access to the root frame of the phone application.
/// </Summary>
/// <Returns> the root frame of the phone application. </returns>
Public phoneapplicationframe rootframe {Get; private set ;}
/// <Summary>
/// Constructor for the Application object.
/// </Summary>
Public app ()
{
Globaldata = new globaldata ();
Globaldata. bitmapimage = new bitmapimage ();
// Global handler for uncaught exceptions.
Unhandledexception + = application_unhandledexception;
......
Mainpage. XAML
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. net;
Using system. windows;
Using system. Windows. controls;
Using system. Windows. documents;
Using system. Windows. input;
Using system. Windows. Media;
Using system. Windows. Media. animation;
Using system. Windows. shapes;
Using Microsoft. Phone. controls;
Using Microsoft. Phone. tasks;
Using system. Windows. Navigation;
Namespace photoapp
{
Public partial class mainpage: phoneapplicationpage
{
Photochoosertask;
// Constructor
Public mainpage ()
{
Initializecomponent ();
Photochoosertask = new photochoosertask ();
Photochoosertask. Completed + = new eventhandler <photoresult> (photochoosertask_completed );
}
Void photochoosertask_completed (Object sender, photoresult E)
{
If (E. taskresult = taskresult. OK)
{
App. globaldata. bitmapimage. setsource (E. chosenphoto );
// Navigationservice. navigate (New uri ("/photopage. XAML", urikind. Relative ));
Navigationservice. navigated + = new navigatedeventhandler (navigatecompleted );
}
}
Void navigatecompleted (Object sender, eventargs E)
{
// Do the delayed navigation from the main page
This. navigationservice. navigate (New uri ("/photopage. XAML", urikind. Relative ));
Navigationservice. navigated-= new navigatedeventhandler (navigatecompleted );
}
/// <Summary>
/// Select a photo
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void button#click (Object sender, routedeventargs E)
{
Photochoosertask. Show ();
}
}
}
Photopage. XAML
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. net;
Using system. windows;
Using system. Windows. controls;
Using system. Windows. documents;
Using system. Windows. input;
Using system. Windows. Media;
Using system. Windows. Media. animation;
Using system. Windows. shapes;
Using Microsoft. Phone. controls;
Namespace photoapp
{
Public partial class photopage: phoneapplicationpage
{
Public photopage ()
{
Initializecomponent ();
}
Protected override void onnavigatedto (system. Windows. Navigation. navigationeventargs E)
{
Base. onnavigatedto (E );
Image1.source = app. globaldata. bitmapimage;
}
}
}