diff --git a/MyFirstMauiApp/NotesNet8/AppShell.xaml b/MyFirstMauiApp/NotesNet8/AppShell.xaml
index ec92af7..b7b81b8 100644
--- a/MyFirstMauiApp/NotesNet8/AppShell.xaml
+++ b/MyFirstMauiApp/NotesNet8/AppShell.xaml
@@ -3,17 +3,17 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:NotesNet8"
- xmlns:page="clr-namespace:NotesNet8.Pages"
+ xmlns:views="clr-namespace:NotesNet8.Views"
Title="NotesNet8"
Shell.FlyoutBehavior="Disabled">
diff --git a/MyFirstMauiApp/NotesNet8/AppShell.xaml.cs b/MyFirstMauiApp/NotesNet8/AppShell.xaml.cs
index 4d4d359..334b8cf 100644
--- a/MyFirstMauiApp/NotesNet8/AppShell.xaml.cs
+++ b/MyFirstMauiApp/NotesNet8/AppShell.xaml.cs
@@ -5,6 +5,12 @@
public AppShell()
{
InitializeComponent();
+ RegisterRoutes();
+ }
+
+ private void RegisterRoutes()
+ {
+ Routing.RegisterRoute(nameof(Views.NotePage), typeof(Views.NotePage));
}
}
}
diff --git a/MyFirstMauiApp/NotesNet8/Models/About.cs b/MyFirstMauiApp/NotesNet8/Models/About.cs
new file mode 100644
index 0000000..79e65a8
--- /dev/null
+++ b/MyFirstMauiApp/NotesNet8/Models/About.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace NotesNet8.Models
+{
+ internal class About
+ {
+ public string Title => AppInfo.Name;
+ public string Version => AppInfo.VersionString;
+ public string MoreInfoUrl => "https://aka.ms/maui";
+ public string Message => "This app is written in XAML and C# with .NET MAUI";
+ }
+}
diff --git a/MyFirstMauiApp/NotesNet8/Models/AllNotes.cs b/MyFirstMauiApp/NotesNet8/Models/AllNotes.cs
new file mode 100644
index 0000000..0ef9559
--- /dev/null
+++ b/MyFirstMauiApp/NotesNet8/Models/AllNotes.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace NotesNet8.Models
+{
+ internal class AllNotes
+ {
+ public ObservableCollection Notes { get; set; } = new ObservableCollection();
+
+ public AllNotes()
+ {
+ LoadNotes();
+ }
+ public void LoadNotes()
+ {
+ Notes.Clear();
+
+ string appDataPath = FileSystem.AppDataDirectory;
+ IEnumerable notes = Directory
+ .EnumerateFiles(appDataPath, "*.notes.txt")
+ .Select(filename => new Note()
+ {
+ Filename = filename,
+ Text = File.ReadAllText(filename),
+ Date = File.GetCreationTime(filename)
+ })
+ .OrderBy(note => note.Date);
+
+ foreach (Note note in notes)
+ {
+ Notes.Add(note);
+ }
+ }
+ }
+}
diff --git a/MyFirstMauiApp/NotesNet8/Models/Note.cs b/MyFirstMauiApp/NotesNet8/Models/Note.cs
new file mode 100644
index 0000000..1e059c6
--- /dev/null
+++ b/MyFirstMauiApp/NotesNet8/Models/Note.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace NotesNet8.Models
+{
+ internal class Note
+ {
+ public string Filename { get; set; }
+ public string Text { get; set; }
+ public DateTime Date { get; set; }
+ }
+}
diff --git a/MyFirstMauiApp/NotesNet8/NotesNet8.csproj b/MyFirstMauiApp/NotesNet8/NotesNet8.csproj
index f055842..84f530b 100644
--- a/MyFirstMauiApp/NotesNet8/NotesNet8.csproj
+++ b/MyFirstMauiApp/NotesNet8/NotesNet8.csproj
@@ -68,10 +68,13 @@
-
+
MSBuild:Compile
-
+
+ MSBuild:Compile
+
+
MSBuild:Compile
diff --git a/MyFirstMauiApp/NotesNet8/Pages/NotePage.xaml.cs b/MyFirstMauiApp/NotesNet8/Pages/NotePage.xaml.cs
deleted file mode 100644
index ad25342..0000000
--- a/MyFirstMauiApp/NotesNet8/Pages/NotePage.xaml.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-namespace NotesNet8.Pages;
-
-public partial class NotePage : ContentPage
-{
- string _fileName = Path.Combine(FileSystem.AppDataDirectory, "notes.txt");
-
- public NotePage()
- {
- InitializeComponent();
-
- if (File.Exists(_fileName))
- TextEditor.Text = File.ReadAllText(_fileName);
- }
-
- private void SaveButton_Clicked(object sender, EventArgs e)
- {
- File.WriteAllText(_fileName, TextEditor.Text);
- }
-
- private void DeleteButton_Clicked(object sender, EventArgs e)
- {
- if (File.Exists(_fileName))
- File.Delete(_fileName);
-
- TextEditor.Text = string.Empty;
- }
-}
\ No newline at end of file
diff --git a/MyFirstMauiApp/NotesNet8/Pages/AboutPage.xaml b/MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml
similarity index 51%
rename from MyFirstMauiApp/NotesNet8/Pages/AboutPage.xaml
rename to MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml
index b3fd847..78a7114 100644
--- a/MyFirstMauiApp/NotesNet8/Pages/AboutPage.xaml
+++ b/MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml
@@ -1,16 +1,25 @@
-
+
+
+
+
-
-
+
+
-
+
\ No newline at end of file
diff --git a/MyFirstMauiApp/NotesNet8/Pages/AboutPage.xaml.cs b/MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml.cs
similarity index 52%
rename from MyFirstMauiApp/NotesNet8/Pages/AboutPage.xaml.cs
rename to MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml.cs
index c33513b..c1b3016 100644
--- a/MyFirstMauiApp/NotesNet8/Pages/AboutPage.xaml.cs
+++ b/MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml.cs
@@ -1,4 +1,4 @@
-namespace NotesNet8.Pages;
+namespace NotesNet8.Views;
public partial class AboutPage : ContentPage
{
@@ -9,6 +9,9 @@ public partial class AboutPage : ContentPage
private async void LearnMore_Clicked(object sender, EventArgs e)
{
- await Launcher.Default.OpenAsync("https://aka.ms/maui");
+ if (BindingContext is Models.About about)
+ {
+ await Launcher.Default.OpenAsync(about.MoreInfoUrl);
+ }
}
}
\ No newline at end of file
diff --git a/MyFirstMauiApp/NotesNet8/Views/AllNotesPage.xaml b/MyFirstMauiApp/NotesNet8/Views/AllNotesPage.xaml
new file mode 100644
index 0000000..30416d6
--- /dev/null
+++ b/MyFirstMauiApp/NotesNet8/Views/AllNotesPage.xaml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MyFirstMauiApp/NotesNet8/Views/AllNotesPage.xaml.cs b/MyFirstMauiApp/NotesNet8/Views/AllNotesPage.xaml.cs
new file mode 100644
index 0000000..27b9343
--- /dev/null
+++ b/MyFirstMauiApp/NotesNet8/Views/AllNotesPage.xaml.cs
@@ -0,0 +1,34 @@
+namespace NotesNet8.Views;
+
+public partial class AllNotesPage : ContentPage
+{
+ public AllNotesPage()
+ {
+ InitializeComponent();
+
+ BindingContext = new Models.AllNotes();
+ }
+
+ protected override void OnAppearing()
+ {
+ base.OnAppearing();
+
+ ((Models.AllNotes)BindingContext).LoadNotes();
+ }
+
+ private async void Add_Clicked(object sender, EventArgs e)
+ {
+ await Shell.Current.GoToAsync(nameof(NotePage));
+ }
+
+ private async void notesCollection_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (e.CurrentSelection.Count == 0)
+ return;
+
+ var note = (Models.Note)e.CurrentSelection[0];
+ await Shell.Current.GoToAsync($"{nameof(NotePage)}?{nameof(NotePage.ItemId)}={note.Filename}");
+
+ notesCollection.SelectedItem = null;
+ }
+}
\ No newline at end of file
diff --git a/MyFirstMauiApp/NotesNet8/Pages/NotePage.xaml b/MyFirstMauiApp/NotesNet8/Views/NotePage.xaml
similarity index 72%
rename from MyFirstMauiApp/NotesNet8/Pages/NotePage.xaml
rename to MyFirstMauiApp/NotesNet8/Views/NotePage.xaml
index 0fba45e..8fb0678 100644
--- a/MyFirstMauiApp/NotesNet8/Pages/NotePage.xaml
+++ b/MyFirstMauiApp/NotesNet8/Views/NotePage.xaml
@@ -1,11 +1,17 @@
-
+
+
+
+
+ HeightRequest="100" Placeholder="Enter your note"
+ Text="{Binding Text}"/>
diff --git a/MyFirstMauiApp/NotesNet8/Views/NotePage.xaml.cs b/MyFirstMauiApp/NotesNet8/Views/NotePage.xaml.cs
new file mode 100644
index 0000000..de5f340
--- /dev/null
+++ b/MyFirstMauiApp/NotesNet8/Views/NotePage.xaml.cs
@@ -0,0 +1,50 @@
+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("..");
+ }
+}
\ No newline at end of file