diff --git a/winui-learning/winui-learning/App.xaml.cs b/winui-learning/winui-learning/App.xaml.cs
index 136201d..936e62f 100644
--- a/winui-learning/winui-learning/App.xaml.cs
+++ b/winui-learning/winui-learning/App.xaml.cs
@@ -1,20 +1,4 @@
using Microsoft.UI.Xaml;
-using Microsoft.UI.Xaml.Controls;
-using Microsoft.UI.Xaml.Controls.Primitives;
-using Microsoft.UI.Xaml.Data;
-using Microsoft.UI.Xaml.Input;
-using Microsoft.UI.Xaml.Media;
-using Microsoft.UI.Xaml.Navigation;
-using Microsoft.UI.Xaml.Shapes;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
-using Windows.ApplicationModel;
-using Windows.ApplicationModel.Activation;
-using Windows.Foundation;
-using Windows.Foundation.Collections;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
diff --git a/winui-learning/winui-learning/MainWindow.xaml b/winui-learning/winui-learning/MainWindow.xaml
index 132acfc..672a488 100644
--- a/winui-learning/winui-learning/MainWindow.xaml
+++ b/winui-learning/winui-learning/MainWindow.xaml
@@ -31,7 +31,7 @@
-
+
diff --git a/winui-learning/winui-learning/MainWindow.xaml.cs b/winui-learning/winui-learning/MainWindow.xaml.cs
index cafae12..0bc5dca 100644
--- a/winui-learning/winui-learning/MainWindow.xaml.cs
+++ b/winui-learning/winui-learning/MainWindow.xaml.cs
@@ -13,6 +13,8 @@ public sealed partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
+ ExtendsContentIntoTitleBar = true;
+ SetTitleBar(AppTitleBar);
}
}
diff --git a/winui-learning/winui-learning/Models/AllNotesModel.cs b/winui-learning/winui-learning/Models/AllNotesModel.cs
new file mode 100644
index 0000000..6c98e59
--- /dev/null
+++ b/winui-learning/winui-learning/Models/AllNotesModel.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Threading.Tasks;
+using Windows.Storage;
+
+namespace winui_learning.Models;
+
+public class AllNotesModel
+{
+ public ObservableCollection Notes { get; set; } = new ObservableCollection();
+
+ public AllNotesModel()
+ {
+ LoadNotes();
+ }
+
+ public async void LoadNotes()
+ {
+ Notes.Clear();
+ // Get the folder where the notes are stored.
+ StorageFolder storageFolder =
+ ApplicationData.Current.LocalFolder;
+ await GetFilesInFolderAsync(storageFolder);
+ }
+
+ private async Task GetFilesInFolderAsync(StorageFolder folder)
+ {
+ // Each StorageItem can be either a folder or a file.
+ IReadOnlyList storageItems =
+ await folder.GetItemsAsync();
+ foreach (IStorageItem item in storageItems)
+ {
+ if (item.IsOfType(StorageItemTypes.Folder))
+ {
+ // Recursively get items from subfolders.
+ await GetFilesInFolderAsync((StorageFolder)item);
+ }
+ else if (item.IsOfType(StorageItemTypes.File))
+ {
+ StorageFile file = (StorageFile)item;
+ NoteModel note = new NoteModel()
+ {
+ Filename = file.Name,
+ Text = await FileIO.ReadTextAsync(file),
+ Date = file.DateCreated.DateTime
+ };
+ Notes.Add(note);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/winui-learning/winui-learning/Models/NoteModel.cs b/winui-learning/winui-learning/Models/NoteModel.cs
index a62ec7a..830ea8a 100644
--- a/winui-learning/winui-learning/Models/NoteModel.cs
+++ b/winui-learning/winui-learning/Models/NoteModel.cs
@@ -1,12 +1,41 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
+using Windows.Storage;
namespace winui_learning.Models
{
- internal class NoteModel
+ public class NoteModel
{
+ private StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
+ public string Filename { get; set; } = string.Empty;
+ public string Text { get; set; } = string.Empty;
+ public DateTime Date { get; set; } = DateTime.Now;
+
+ public NoteModel()
+ {
+ Filename = "notes" + DateTime.Now.ToBinary().ToString() + ".txt";
+ }
+
+ public async Task SaveAsync()
+ {
+ // Save the note to a file.
+ StorageFile noteFile = (StorageFile)await storageFolder.TryGetItemAsync(Filename);
+ if (noteFile is null)
+ {
+ noteFile = await storageFolder.CreateFileAsync(Filename, CreationCollisionOption.ReplaceExisting);
+ }
+ await FileIO.WriteTextAsync(noteFile, Text);
+ }
+
+ public async Task DeleteAsync()
+ {
+ // Delete the note from the file system.
+ StorageFile noteFile = (StorageFile)await storageFolder.TryGetItemAsync(Filename);
+ if (noteFile is not null)
+ {
+ await noteFile.DeleteAsync();
+ }
+ }
}
}
+
diff --git a/winui-learning/winui-learning/Views/AllNotesPage.xaml b/winui-learning/winui-learning/Views/AllNotesPage.xaml
new file mode 100644
index 0000000..55a27f0
--- /dev/null
+++ b/winui-learning/winui-learning/Views/AllNotesPage.xaml
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/winui-learning/winui-learning/Views/AllNotesPage.xaml.cs b/winui-learning/winui-learning/Views/AllNotesPage.xaml.cs
new file mode 100644
index 0000000..1fc321d
--- /dev/null
+++ b/winui-learning/winui-learning/Views/AllNotesPage.xaml.cs
@@ -0,0 +1,18 @@
+using Microsoft.UI.Xaml.Controls;
+using winui_learning.Models;
+
+// To learn more about WinUI, the WinUI project structure,
+// and more about our project templates, see: http://aka.ms/winui-project-info.
+
+namespace winui_learning.Views
+{
+ public sealed partial class AllNotesPage : Page
+ {
+ public AllNotesModel allNotesModel = new AllNotesModel();
+
+ public AllNotesPage()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/winui-learning/winui-learning/Views/NotePage.xaml b/winui-learning/winui-learning/Views/NotePage.xaml
index 93fc499..c3c7a19 100644
--- a/winui-learning/winui-learning/Views/NotePage.xaml
+++ b/winui-learning/winui-learning/Views/NotePage.xaml
@@ -19,21 +19,23 @@
-
+
-
-
+
+
diff --git a/winui-learning/winui-learning/Views/NotePage.xaml.cs b/winui-learning/winui-learning/Views/NotePage.xaml.cs
index 582f521..5a7bc7a 100644
--- a/winui-learning/winui-learning/Views/NotePage.xaml.cs
+++ b/winui-learning/winui-learning/Views/NotePage.xaml.cs
@@ -1,19 +1,6 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
-using Microsoft.UI.Xaml.Controls.Primitives;
-using Microsoft.UI.Xaml.Data;
-using Microsoft.UI.Xaml.Input;
-using Microsoft.UI.Xaml.Media;
-using Microsoft.UI.Xaml.Navigation;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
-using System.Threading.Tasks;
-using Windows.Foundation;
-using Windows.Foundation.Collections;
-using Windows.Storage;
+using winui_learning.Models;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
@@ -25,42 +12,26 @@ namespace winui_learning.Views
///
public sealed partial class NotePage : Page
{
- private StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
- private StorageFile? noteFile = null;
- private string fileName = "note.txt";
+ private NoteModel? note;
public NotePage()
{
InitializeComponent();
- Loaded += NotePage_Loaded;
}
- private async void NotePage_Loaded(object sender, RoutedEventArgs e)
+ private async void ButtonClick_Save(object sender, RoutedEventArgs e)
{
- noteFile = (StorageFile)await storageFolder.TryGetItemAsync(fileName);
-
- if (noteFile is not null)
+ if (note is not null)
{
- NoteEditor.Text = await FileIO.ReadTextAsync(noteFile);
+ await note.SaveAsync();
}
}
- private async void Save(object sender, RoutedEventArgs e)
+ private async void ButtonClick_Delete(object sender, RoutedEventArgs e)
{
- if (noteFile is null)
+ if (note is not null)
{
- noteFile = await storageFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
- }
- await FileIO.WriteTextAsync(noteFile, NoteEditor.Text);
- }
-
- private async void Delete(object sender, RoutedEventArgs e)
- {
- if (noteFile is not null)
- {
- await noteFile.DeleteAsync();
- noteFile = null;
- NoteEditor.Text = string.Empty;
+ await note.DeleteAsync();
}
}
}
diff --git a/winui-learning/winui-learning/winui-learning.csproj b/winui-learning/winui-learning/winui-learning.csproj
index 017cfd7..db2d8a7 100644
--- a/winui-learning/winui-learning/winui-learning.csproj
+++ b/winui-learning/winui-learning/winui-learning.csproj
@@ -1,4 +1,4 @@
-
+
WinExe
net8.0-windows10.0.19041.0
@@ -50,7 +50,9 @@
-
+
+ MSBuild:Compile
+