StorageFile是否包含数据(windwos手机)

时间:2016-12-24 15:21:06

标签: c# windows-phone-8.1 windows-phone-silverlight

如何获取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

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

1 个答案:

答案 0 :(得分:1)

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

if ( AreaTextBox.Text == "" ) 
{
      AreaTextBox.Text = "1.8";
}