Skip to content

Commit

Permalink
Note page (#2)
Browse files Browse the repository at this point in the history
* Added NotePage

* Added content to NotePage.xaml

* Added fuctionality to NotePage, added NotePage to AppShell
  • Loading branch information
AnrdyShmrdy authored Nov 2, 2022
1 parent f7c7042 commit e72e314
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Notes/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<TabBar>
<ShellContent
Title="Notes"
ContentTemplate="{DataTemplate local:MainPage}"
ContentTemplate="{DataTemplate local:NotePage}"
Icon="icon_notes" />

<ShellContent
Expand Down
20 changes: 20 additions & 0 deletions Notes/NotePage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Notes.NotePage"
Title="Note">
<VerticalStackLayout Spacing="10" Margin="5">
<Editor x:Name="TextEditor"
Placeholder="Enter your note"
HeightRequest="100" />

<Grid ColumnDefinitions="*,*" ColumnSpacing="4">
<Button Text="Save"
Clicked="SaveButton_Clicked" />

<Button Grid.Column="1"
Text="Delete"
Clicked="DeleteButton_Clicked" />
</Grid>
</VerticalStackLayout>
</ContentPage>
28 changes: 28 additions & 0 deletions Notes/NotePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Notes;

public partial class NotePage : ContentPage
{
string _fileName = Path.Combine(FileSystem.AppDataDirectory, "notes.txt");
//The code above constructs a path to the file, storing it in the app's local data directory. The file name is notes.txt.
public NotePage()
{
InitializeComponent();
//read the file from the device and store its contents in the TextEditor control's Text property:
if (File.Exists(_fileName))
TextEditor.Text = File.ReadAllText(_fileName);
}
private void SaveButton_Clicked(object sender, EventArgs e)
{
// Save the file.
File.WriteAllText(_fileName, TextEditor.Text);
}

private void DeleteButton_Clicked(object sender, EventArgs e)
{
// Delete the file.
if (File.Exists(_fileName))
File.Delete(_fileName);

TextEditor.Text = string.Empty;
}
}
3 changes: 3 additions & 0 deletions Notes/Notes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<MauiXaml Update="AboutPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="NotePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>

0 comments on commit e72e314

Please sign in to comment.