Dodělání aplikace podle tutoriálu. Nyní lze uložit, smazat a otevírát různé poznámky.
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
x:Class="winui_learning.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:winui_learning"
|
||||
xmlns:views="using:winui_learning.Views"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
@@ -25,7 +24,10 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TitleBar x:Name="AppTitleBar"
|
||||
Title="WinUI Notes">
|
||||
Title="WinUI Notes"
|
||||
IsBackButtonVisible="True"
|
||||
IsBackButtonEnabled="{x:Bind rootFrame.CanGoBack, Mode=OneWay}"
|
||||
BackRequested="AppTitleBar_BackRequested">
|
||||
<TitleBar.IconSource>
|
||||
<FontIconSource Glyph=""/>
|
||||
</TitleBar.IconSource>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using ABI.Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml;
|
||||
using TitleBar = Microsoft.UI.Xaml.Controls.TitleBar;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
@@ -16,5 +18,13 @@ public sealed partial class MainWindow : Window
|
||||
ExtendsContentIntoTitleBar = true;
|
||||
SetTitleBar(AppTitleBar);
|
||||
}
|
||||
|
||||
private void AppTitleBar_BackRequested(TitleBar titleBar, object args)
|
||||
{
|
||||
if (rootFrame.CanGoBack)
|
||||
{
|
||||
rootFrame.GoBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<CommandBar DefaultLabelPosition="Right">
|
||||
<AppBarButton Icon="Add" Label="New note"/>
|
||||
<AppBarButton Icon="Add" Label="New note" Click="NewNoteButton_Click"/>
|
||||
<CommandBar.Content>
|
||||
<TextBlock Text="Quick notes" Margin="16,8"
|
||||
Style="{ThemeResource SubtitleTextBlockStyle}"/>
|
||||
@@ -56,7 +56,10 @@
|
||||
<ItemsView
|
||||
ItemsSource="{x:Bind allNotesModel.Notes}"
|
||||
Grid.Row="1" Padding="16"
|
||||
ItemTemplate="{StaticResource NoteItemTemplate}">
|
||||
ItemTemplate="{StaticResource NoteItemTemplate}"
|
||||
SelectionMode="None"
|
||||
IsItemInvokedEnabled="True"
|
||||
ItemInvoked="ItemsView_ItemInvoked">
|
||||
|
||||
<ItemsView.Layout>
|
||||
<UniformGridLayout MinItemWidth="200"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using winui_learning.Models;
|
||||
|
||||
@@ -14,5 +15,15 @@ namespace winui_learning.Views
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void NewNoteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Frame.Navigate(typeof(NotePage));
|
||||
}
|
||||
|
||||
private void ItemsView_ItemInvoked(ItemsView sender, ItemsViewItemInvokedEventArgs args)
|
||||
{
|
||||
Frame.Navigate(typeof(NotePage), args.InvokedItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
x:Class="winui_learning.Views.NotePage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:winui_learning"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using winui_learning.Models;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
@@ -12,13 +13,20 @@ namespace winui_learning.Views
|
||||
/// </summary>
|
||||
public sealed partial class NotePage : Page
|
||||
{
|
||||
private NoteModel? note;
|
||||
private NoteModel note = new();
|
||||
|
||||
public NotePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
note = e.Parameter as NoteModel ?? new NoteModel();
|
||||
Bindings.Update();
|
||||
}
|
||||
|
||||
private async void ButtonClick_Save(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (note is not null)
|
||||
@@ -33,6 +41,10 @@ namespace winui_learning.Views
|
||||
{
|
||||
await note.DeleteAsync();
|
||||
}
|
||||
if (Frame.CanGoBack)
|
||||
{
|
||||
Frame.GoBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user