Preface (some nonsense ha, can skip)
wp8.1 of the SDK relative 8.0 or change a lot of, the class has changed many, I am I met some of the problems summed up, we can use less to go some detours, some things are not in the domestic search
(Do this person less, data less, start transplant to wp8.1 also less), suggest small partners Google, or keyword search in English better, in fact, I mostly found in StackOverflow,
It's also possible to look at official documents, but it's a bit slower.
Body
The MessageBox was replaced by Messagedialog with the following details (some variable names are readily written, not considered ...). Everyone can change it)
Public Async Static voidShowcustomdialog (stringTitlestringMesstringOK, Action Ok_callback,stringCancel, Action cancel_callback) {Messagedialog C=NewMessagedialog (Mes,title); Uicommand Ok_cmd=NewUicommand (OK); Ok_cmd. Invoked+ = (dd) = = { if(Ok_callback! =NULL) {Ok_callback. Invoke (); } }; Uicommand Canle_cmd=NewUicommand (cancel); Ok_cmd. Invoked+ = (dd) = = { if(Cancel_callback! =NULL) {Cancel_callback. Invoke (); }; }; C.commands.add (Ok_cmd); C.commands.add (Canle_cmd); Iuicommand result=awaitC.showasync (); }
The class Devicestatus to get the basic information of the device is replaced by easclientdeviceinformation basic usage as follows
public static string Getdeviceinfo () { Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation deviceinfo = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation (); var firmwareversion = deviceinfo.systemfirmwareversion; String d = "{\" devicename\ ": \" "+ Deviceinfo.systemproductname +" \ ", \" Devicemanufacturer\ ": \" "+ Deviceinfo.systemmanufacturer + "\"} "; return D; }
The Class Deviceextendedproperties.trygetvalue ("Deviceuniqueid", out uniqueId) that gets the device's unique ID is replaced by hardwareidentification, using the following
public static string Getdeviceuniqueid () { Hardwaretoken token = Hardwareidentification.getpackagespecifictoken (null); IBuffer HardwareID = token. Id; Hashalgorithmprovider hasher = Hashalgorithmprovider.openalgorithm ("MD5"); IBuffer hashed = Hasher. Hashdata (HardwareID); String hashedstring = Cryptographicbuffer.encodetohexstring (hashed); return hashedstring; }
The Deployment.Current.Dispatcher.BeginInvoke used to perform UI process tasks in a background process is corewindow.getforcurrentthread (). Dispatcher substitution, specific usage
var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
Await dispatcher. RunAsync (Coredispatcherpriority.normal, () =
{ //UI code goes here
});
or CoreApplication.MainWindow.CoreWindow.Dispatcher.RunAsync ( coredispatcherpriority.normal, () =>{ //UI code goes here});
The current thread sleep Thread.Sleep()
isawait Task.Delay(1000)取代
Isolatedstoragesettings was replaced by ApplicationData.Current.RoamingSettings, IsolatedStorageFile was ApplicationData.Current.LocalFolder Replace, use the following specifically
public class Isolatedstoragehelper {private static Applicationdatacontainer _appsettings= Applicationdata.curre Nt. Roamingsettings; public static T Loadsetttingfromstorage<t> (string Key, T defaultvalue) {T objtoload = default (t); if (_appsettings.values.keys.contains (Key)) {objtoload = (T) _appsettings.values[key ]; } else {objtoload = defaultvalue; } return objtoload; public static void Savesettingtostorage (String Key, Object Setting) {if (!_appsettings.values. Keys.contains (key)) {_appsettings.values.add (key, Setting); } else {_appsettings.values[key] = Setting; }} public static bool Issettingpersisted (string Key) {return _appsettings.values.ke Ys. Contains (Key); } PubLIC static bool Deletesettingpersisted (string Key) {while (_appsettings.values.keys.contains (Key)) {_appsettings.values.remove (Key); } return false; } public static Async task<bool> Appendstrtofolder (string str) {str = "time:" + DateTime.Now . ToString () + str; Get the Application Data store folder Storagefolder Applicationfolder = ApplicationData.Current.LocalFolder; Creates the specified file within the specified Application data store folder StorageFile StorageFile = await Applicationfolder.createfileasync ("Luapostjsonstr.tx T ", creationcollisionoption.openifexists); Writes the specified text content to the specified file using (Stream stream = await Storagefile.openstreamforwriteasync ()) { byte[] content = Encoding.UTF8.GetBytes (str); Await stream. WriteAsync (content, 0, content. Length); } return true; } public static ASync task<bool> WriteFile (string filename,string content) {content = "time:" + DateTime.Now.ToStrin G () + "--------" + content; Istoragefolder applicationfolder = ApplicationData.Current.LocalFolder; Istoragefile StorageFile = await applicationfolder.createfileasync (filename, creationcollisionoption.openifexists); try {using (Stream transaction = await Storagefile.openstreamforwriteasync ()) {byte[] contents = Encoding.UTF8.GetBytes (content); Set how to open a stream where there is content to set the position of the stream to the end position if (transaction. CanSeek) {transaction. Seek (transaction. Length, Seekorigin.begin); } await transaction. WriteAsync (contents,0, contents. Length); return true; }} catch (Exception Exce) {return false; Outputtextblock.text = "Exception:" + Exce. Message; }} public static async Task savepic (UIElement root, string filename) {RenderTargetBitmap RenderTargetBitmap = new RenderTargetBitmap (); await Rendertargetbitmap.renderasync (root); var pixelbuffer = await rendertargetbitmap.getpixelsasync (); String path = "PICSDK"; Storagefolder storagefolder = ApplicationData.Current.LocalFolder; Storagefolder store = await storagefolder.createfolderasync (path, creationcollisionoption.openifexists); string ss = Path.Combine (Path, filename); StorageFile file = await store. Createfileasync (ss); using (var FileStream = await file. OpenAsync (Fileaccessmode.readwrite)) {var encoder = await Bitmapencoder.createasync (bitmapencod Er. Pngencoderid, FileStream); Encoder. Setpixeldata (Bitmappixelformat.bgra8, Bitmapalphamode.ignore, (UINT) rendertargetbitmap.pixelwidth, (UIn T) Rendertargetbitmap.pixelheight, Displayinformation.getforcurrentview (). LOGICALDPI, Displayinformation.getforcurrentview (). LOGICALDPI, Pixelbuffer.toarray ()); Await encoder. Flushasync (); }} public static async task<bool> SaveFile (StorageFile filee) {String path = " Picsdk "; Storagefolder storagefolder = ApplicationData.Current.LocalFolder; Storagefolder store = await storagefolder.createfolderasync (path, creationcollisionoption.openifexists); string ss = Path.Combine (Path, Filee. Name); StorageFile file = await store. Createfileasync (ss); Await Filee. Moveandreplaceasync (file); return true; } public static Async task< bitmapimage> Loadpic (String folDername,string fileName) {BitmapImage Source = new BitmapImage (); Reopen and load the PNG file. if (await Isexistfolder (folderName)) {var folder = ApplicationData.Current.LocalFolder; if (await Isexistfile (filename,foldername)) {StorageFile file = await folder.g Etfileasync (FileName); using (var FileStream = await file. OpenAsync (Fileaccessmode.readwrite)) {var encoder = await B Itmapdecoder.createasync (Bitmapencoder.pngencoderid, FileStream); var stream = await encoder. Getpreviewasync (); Source. SetSource (stream); Source. CreateOptions = Bitmapcreateoptions.none; }} return source; } else {return null; } public static Async task<bool> Isexistfile (string fileName) {Storagefolder Storag EFolder = ApplicationData.Current.LocalFolder; try {StorageFile file = await storagefolder.getfileasync (fileName); return true; } catch (FileNotFoundException e) {return false; } catch (Exception e) {return false; }} public static async task<bool> Isexistfile (String filename,string folderName) { Storagefolder storagefolder = ApplicationData.Current.LocalFolder; Storagefolder folder= await Storagefolder.getfolderasync (folderName); try {StorageFile file = await folder. Getfileasync (FileName); return true; } catch (FileNotFoundException e) {return false; } catch (Exception e) {return false; }} public static async task<bool> Isexistfolder (string folderName) {Storagefolder Storagefolder = ApplicationData.Current.LocalFolder; try {Storagefolder file = await storagefolder.getfolderasync (folderName); return true; } catch (FileNotFoundException e) {return false; } catch (Exception e) {return false; }} public static async task< stream> Loadpicbystream (string filename) {var store = ApplicationData.Current.LocalFolder; if (await isexistfile (filename)) {StorageFile file= await store. Getfileasync (filename); Filestream.close (); return (await file. OpenAsync (Fileaccessmode.readwrite)). AsstrEAM (); } else {return null; } } }
Finally this class, things compared to Doha, some haven't had time to test, the small partner encountered problems also please tell me. It's time to delay everyone.
Windows Phone 8 APP porting to Windows Phone 8.1 FAQ Summary