0

如何获取 StorageFile 文件包含数据?如果不是那么

AreaTextBlock.Text = "1.8;"

我当前的代码是:

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);

}

在按钮点击 AreaTextBlock.Text 是 1.9 但我需要当按钮从不点击时 AreaTextBlock.Text 应该是 1.8

我不想在 xaml 或 c# 初始化中编写 AreaTextBlock.Text = "1.8",因为当退出并重新启动时,AreaTextBlock.Text 是 1.8,即使它的文本是 1.9。那么怎么做

4

1 回答 1

1

Loaded基本上,您只需要在方法结束时检查是否AreaTextBox.Text为空,如果是,则设置默认值。

if ( AreaTextBox.Text == "" ) 
{
      AreaTextBox.Text = "1.8";
} 
于 2016-12-24T19:47:25.157 回答