Use application settings to implement this functionality.
1. First, get the container for app settings:
Applicationdatacontainer localsettings = ApplicationData.Current.LocalSettings;
Because the key is not assigned to Fireststart when the container is fetched, the following is a direct judge of whether it is NULL, or NULL is the first time the app is run,
Then in else the key is assigned to Fireststart, then the else code can only be executed once. Of course later on the UI can add a Switchbutton to control what, that is to open the brain hole.
1 /// <summary>2 ///Page Loading Tags3 /// </summary>4 /// <param name= "Sender" ></param>5 /// <param name= "E" ></param>6 Private voidPage_loaded (Objectsender, RoutedEventArgs e)7 {8 //interpret if the app is the first to start, and if so, initialize the app's database9 Ten if(localsettings.values["Firststart"] !=NULL) One { A //fills the text of Datetextblock and Timetextboloc -DateTime now =DateTime.Now; -Datetextblock.text = Now. ToString ("YYYY-MM-DD"); theTimetextblock.text = Now. ToString ("HH:mm:ss"); - - //populating the GridView - mark. Clear (); +Mark =Sqlitehelper.readdata (Mark); - } + Else A { at Firststart (); -localsettings.values["Firststart"] =true; - - //fills the text of Datetextblock and Timetextboloc -DateTime now =DateTime.Now; -Datetextblock.text = Now. ToString ("YYYY-MM-DD"); inTimetextblock.text = Now. ToString ("HH:mm:ss"); - to //populating the GridView + mark. Clear (); -Mark =Sqlitehelper.readdata (Mark); the } * $ Panax Notoginseng}
[UWP Little White Diary-1] determine if the app is the first to run the Initialize SQLite database