parent
9039c49ad3
commit
7ef194a4cb
@ -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; |
||||
} |
||||
} |
@ -1,16 +1,25 @@ |
||||
<?xml version="1.0" encoding="utf-8" ?> |
||||
<ContentPage x:Class="NotesNet8.Pages.AboutPage" |
||||
<ContentPage x:Class="NotesNet8.Views.AboutPage" |
||||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
xmlns:models="clr-namespace:NotesNet8.Models" |
||||
Title="AboutPage"> |
||||
<ContentPage.BindingContext> |
||||
<models:About /> |
||||
</ContentPage.BindingContext> |
||||
|
||||
<VerticalStackLayout Margin="10" Spacing="10"> |
||||
<HorizontalStackLayout Spacing="10"> |
||||
<Image HeightRequest="64" SemanticProperties.Description="The dot net bot waving hello!" Source="dotnet_bot.png" /> |
||||
<Label FontAttributes="Bold" FontSize="22" Text="Notes" VerticalOptions="End" /> |
||||
<Label FontSize="22" Text="v1.0" VerticalOptions="End" /> |
||||
<Label FontAttributes="Bold" FontSize="22" |
||||
Text="{Binding Title}" |
||||
VerticalOptions="End" /> |
||||
<Label FontSize="22" |
||||
Text="{Binding Version}" |
||||
VerticalOptions="End" /> |
||||
</HorizontalStackLayout> |
||||
|
||||
<Label Text="This app is written in XAML and C# with .NET MAUI" /> |
||||
<Label Text="{Binding Message}" /> |
||||
<Button Clicked="LearnMore_Clicked" Text="Learn more..." /> |
||||
</VerticalStackLayout> |
||||
</ContentPage> |
@ -0,0 +1,37 @@ |
||||
<?xml version="1.0" encoding="utf-8" ?> |
||||
<ContentPage x:Class="NotesNet8.Views.AllNotesPage" |
||||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
xmlns:models="clr-namespace:NotesNet8.Models" |
||||
Title="AllNotesPage"> |
||||
<ContentPage.ToolbarItems> |
||||
<ToolbarItem Clicked="Add_Clicked" |
||||
IconImageSource="{FontImage Glyph='+', |
||||
Color=Black, |
||||
Size=22}" |
||||
Text="Add" /> |
||||
</ContentPage.ToolbarItems> |
||||
<ContentPage.BindingContext> |
||||
<models:AllNotes /> |
||||
</ContentPage.BindingContext> |
||||
|
||||
<CollectionView x:Name="notesCollection" |
||||
Margin="20" |
||||
ItemsSource="{Binding Notes}" |
||||
SelectionChanged="notesCollection_SelectionChanged" SelectionMode="Single"> |
||||
<CollectionView.ItemsLayout> |
||||
<LinearItemsLayout ItemSpacing="10" Orientation="Vertical" /> |
||||
</CollectionView.ItemsLayout> |
||||
|
||||
<CollectionView.ItemTemplate> |
||||
<DataTemplate> |
||||
<StackLayout> |
||||
<Label FontSize="22" Text="{Binding Text}" /> |
||||
<Label FontSize="14" |
||||
Text="{Binding Date}" |
||||
TextColor="Silver" /> |
||||
</StackLayout> |
||||
</DataTemplate> |
||||
</CollectionView.ItemTemplate> |
||||
</CollectionView> |
||||
</ContentPage> |
@ -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; |
||||
} |
||||
} |
@ -1,11 +1,17 @@ |
||||
<?xml version="1.0" encoding="utf-8" ?> |
||||
<ContentPage x:Class="NotesNet8.Pages.NotePage" |
||||
<ContentPage x:Class="NotesNet8.Views.NotePage" |
||||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
xmlns:models="clr-namespace:NotesNet8.Models" |
||||
Title="NotePage"> |
||||
<ContentPage.BindingContext> |
||||
<models:Note /> |
||||
</ContentPage.BindingContext> |
||||
|
||||
<VerticalStackLayout Margin="5" Spacing="10"> |
||||
<Editor x:Name="TextEditor" |
||||
HeightRequest="100" Placeholder="Enter your note" /> |
||||
HeightRequest="100" Placeholder="Enter your note" |
||||
Text="{Binding Text}"/> |
||||
<Grid ColumnDefinitions="*,*" ColumnSpacing="4"> |
||||
<Button Grid.Column="0" |
||||
Clicked="SaveButton_Clicked" Text="Save" /> |
@ -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(".."); |
||||
} |
||||
} |
Loading…
Reference in new issue