Reputation: 2015
How to get StorageFile file contain data ? if not then
AreaTextBlock.Text = "1.8;"
my current code is:
private async void Button_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("text.txt", CreationCollisionOption.OpenIfExists);
await FileIO.WriteTextAsync(file, "1.9");
}
private async void SettingsPage_Loaded(object sender, RoutedEventArgs e)
{
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("text.txt", CreationCollisionOption.OpenIfExists);
AreaTextBlock.Text = await FileIO.ReadTextAsync(file);
}
on button tap AreaTextBlock.Text is 1.9 but i need when button is never tapped then AreaTextBlock.Text should be 1.8
i didn't want to write AreaTextBlock.Text = "1.8" in xaml or in c# initialize because when exit and relaunch AreaTextBlock.Text is 1.8 even if its text is 1.9. so how to do that
Upvotes: 0
Views: 29
Reputation: 39102
Basically all you need is to check at the end of the Loaded
method if the AreaTextBox.Text
is empty and if yes, set the default value.
if ( AreaTextBox.Text == "" )
{
AreaTextBox.Text = "1.8";
}
Upvotes: 1