Hello all. the problem is in the this section InputTB.Text = "''; not work inside task but work outside task pleas what wrong thank you . Finally I change to bool answer = await DisplayAlert() if(answer) {...} and that works ok but I still curious why in the task no works
answer.ContinueWith(async task =>
{
if (task.Result)
{
saveForAWhile += InputTB.Text; // this not work
InputTB.Text = " "; // this not work
}
});
<Label HorizontalOptions="Center" VerticalOptions="End"
FontAttributes="Bold" Text="Puzzle Window" >
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapClearPuzzleWindow"
NumberOfTapsRequired="2" />
</Label.GestureRecognizers>
</Label>
<Label x:Name="Open" Text="Open" FontAttributes="Bold"
HorizontalOptions="Start" VerticalOptions="Center"
Grid.Row="0" Grid.Column="1" >
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapDeletePuzzlsList"
NumberOfTapsRequired="2" />
</Label.GestureRecognizers>
</Label>
private void OnTapDeletePuzzlsList(object sender, TappedEventArgs e)
{
string msg = "Delete Puzzles List file?";
Task<bool> answer = DisplayAlert("", msg, "Yes", "No");
answer.ContinueWith(async task =>
{
if (task.Result)
{
string savetime = DateTime.Now.ToString();
string targetFile = System.IO.Path.Combine(FileSystem.Current.AppDataDirectory, "PuzzlesList.txt");
savedPuzzlesList = "\n Puzzles List: " + savetime + "\n\n";
File.Delete(targetFile);
// Write the file content to the app data directory
using FileStream outputStream = System.IO.File.OpenWrite(targetFile);
using StreamWriter streamWriter = new StreamWriter(outputStream);
await streamWriter.WriteAsync(savedPuzzlesList);
}
});
}
private void OnTapClearPuzzleWindow(object sender, TappedEventArgs e)
{
string msg = "Clear Puzzle Window?";
Task<bool> answer = DisplayAlert("", msg, "Yes", "No");
answer.ContinueWith(async task =>
{
if (task.Result)
{
saveForAWhile += InputTB.Text;
InputTB.Text = " ";
}
});
}