<Page
x:Class="pc.NavigateExample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBox x:Name="Input_TextBox" />
<Button x:Name="Save_Button" Click="Save_Button_Click" Content="Save"/>
</StackPanel>
</Grid>
</Page>
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System;
using System.Threading.Tasks;
using Windows.UI.Popups;
using Windows.UI.Core;
namespace pc.NavigateExample
{
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
Task.Run(async () =>
{
var roamingFolder = ApplicationData.Current.RoamingFolder;
var storageFile = await roamingFolder.GetFileAsync("data.txt");
if (storageFile != null)
return storageFile;
throw new ArgumentNullException();
}).ContinueWith(async tr =>
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
if (tr.Status == TaskStatus.Faulted)
await new MessageDialog("No File detected").ShowAsync();
else
Input_TextBox.Text = await FileIO.ReadTextAsync(tr.Result);
});
});
}
async void
Save_Button_Click(object sender, RoutedEventArgs e)
{
var parameter = Input_TextBox.Text;
var roamingFolder = ApplicationData.Current.RoamingFolder;
var storageFile = await roamingFolder.CreateFileAsync("data.txt",
CreationCollisionOption.ReplaceExisting);
await FileIO.WriteTextAsync(storageFile, parameter);
}
}
}