You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1.3 KiB

namespace NotesNet8.Views;
[QueryProperty(nameof(ItemId), nameof(ItemId))]
public partial class NotePage : ContentPage
{
public string ItemId { set { LoadNote(value); } }
public NotePage()
{
InitializeComponent();
string appDataPath = FileSystem.AppDataDirectory;
string randomFileName = $"{Path.GetRandomFileName()}.notes.txt";
LoadNote(Path.Combine(appDataPath, randomFileName));
}
private void LoadNote(string fileName)
{
Models.Note noteModel = new Models.Note();
noteModel.Filename = fileName;
if (File.Exists(fileName))
{
noteModel.Date = File.GetCreationTime(fileName);
noteModel.Text = File.ReadAllText(fileName);
}
BindingContext = noteModel;
}
private async void SaveButton_Clicked(object sender, EventArgs e)
{
if (BindingContext is Models.Note note)
File.WriteAllText(note.Filename, TextEditor.Text);
await Shell.Current.GoToAsync("..");
}
private async void DeleteButton_Clicked(object sender, EventArgs e)
{
if (BindingContext is Models.Note note)
{
if (File.Exists(note.Filename))
File.Delete(note.Filename);
}
await Shell.Current.GoToAsync("..");
}
}