notes app
This commit is contained in:
25
MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml
Normal file
25
MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<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="{Binding Title}"
|
||||
VerticalOptions="End" />
|
||||
<Label FontSize="22"
|
||||
Text="{Binding Version}"
|
||||
VerticalOptions="End" />
|
||||
</HorizontalStackLayout>
|
||||
|
||||
<Label Text="{Binding Message}" />
|
||||
<Button Clicked="LearnMore_Clicked" Text="Learn more..." />
|
||||
</VerticalStackLayout>
|
||||
</ContentPage>
|
17
MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml.cs
Normal file
17
MyFirstMauiApp/NotesNet8/Views/AboutPage.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace NotesNet8.Views;
|
||||
|
||||
public partial class AboutPage : ContentPage
|
||||
{
|
||||
public AboutPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void LearnMore_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
if (BindingContext is Models.About about)
|
||||
{
|
||||
await Launcher.Default.OpenAsync(about.MoreInfoUrl);
|
||||
}
|
||||
}
|
||||
}
|
37
MyFirstMauiApp/NotesNet8/Views/AllNotesPage.xaml
Normal file
37
MyFirstMauiApp/NotesNet8/Views/AllNotesPage.xaml
Normal file
@@ -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>
|
34
MyFirstMauiApp/NotesNet8/Views/AllNotesPage.xaml.cs
Normal file
34
MyFirstMauiApp/NotesNet8/Views/AllNotesPage.xaml.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
22
MyFirstMauiApp/NotesNet8/Views/NotePage.xaml
Normal file
22
MyFirstMauiApp/NotesNet8/Views/NotePage.xaml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<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"
|
||||
Text="{Binding Text}"/>
|
||||
<Grid ColumnDefinitions="*,*" ColumnSpacing="4">
|
||||
<Button Grid.Column="0"
|
||||
Clicked="SaveButton_Clicked" Text="Save" />
|
||||
<Button Grid.Column="1"
|
||||
Clicked="DeleteButton_Clicked" Text="Delete" />
|
||||
</Grid>
|
||||
</VerticalStackLayout>
|
||||
</ContentPage>
|
50
MyFirstMauiApp/NotesNet8/Views/NotePage.xaml.cs
Normal file
50
MyFirstMauiApp/NotesNet8/Views/NotePage.xaml.cs
Normal file
@@ -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("..");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user