Skip to content

Commit bebd9d0

Browse files
Merge pull request #4 from shweaver-MSFT/newNotePages
Added ability to create new note pages and navigate between them
2 parents dea8d6a + ce6a93a commit bebd9d0

File tree

6 files changed

+192
-54
lines changed

6 files changed

+192
-54
lines changed

ContosoNotes/Models/NotePageModel.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,24 @@ public string PageTitle
2121
public ObservableCollection<NoteItemModel> NoteItems
2222
{
2323
get => _noteItems;
24-
set => SetProperty(ref _noteItems, value);
24+
private set => SetProperty(ref _noteItems, value);
2525
}
2626

2727
[JsonIgnore]
28-
public bool IsEmpty => _noteItems == null || _noteItems.Count == 0 || (_noteItems.Count == 1 && string.IsNullOrWhiteSpace(_noteItems[0].Text));
28+
public bool IsEmpty => string.IsNullOrEmpty(_pageTitle) && (_noteItems.Count == 0 || (_noteItems.Count == 1 && string.IsNullOrWhiteSpace(_noteItems[0].Text)));
2929

3030
public NotePageModel()
3131
{
3232
Id = Guid.NewGuid().ToString();
33-
NoteItems = new ObservableCollection<NoteItemModel>();
33+
_pageTitle = string.Empty;
34+
_noteItems = new ObservableCollection<NoteItemModel>();
3435
}
3536

3637
public NotePageModel(string id = null, string pageTitle = null, IEnumerable<NoteItemModel> noteItems = null)
3738
{
3839
Id = id ?? Guid.NewGuid().ToString();
39-
PageTitle = pageTitle;
40-
NoteItems = noteItems != null ? new ObservableCollection<NoteItemModel>(noteItems) : new ObservableCollection<NoteItemModel>();
40+
_pageTitle = pageTitle;
41+
_noteItems = noteItems != null ? new ObservableCollection<NoteItemModel>(noteItems) : new ObservableCollection<NoteItemModel>();
4142
}
4243
}
4344
}

ContosoNotes/StorageManager.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,18 @@ public async Task<NotePageModel> GetNotePageAsync(NotesListItemModel notesListIt
119119
{
120120
var notePageFileName = GetNotePageFileName(notesListItemModel);
121121

122-
return _roamingStorageHelper != null
123-
? await _roamingStorageHelper.ReadFileAsync<NotePageModel>(notePageFileName)
124-
: await _localStorageHelper.ReadFileAsync<NotePageModel>(notePageFileName);
122+
if (_roamingStorageHelper != null)
123+
{
124+
try
125+
{
126+
return await _roamingStorageHelper.ReadFileAsync<NotePageModel>(notePageFileName);
127+
}
128+
catch
129+
{
130+
}
131+
}
132+
133+
return await _localStorageHelper.ReadFileAsync<NotePageModel>(notePageFileName);
125134
}
126135

127136
private async Task<NotePageModel> GetCurrentNotePage(IObjectStorageHelper storageHelper, NotesListModel notesList)

ContosoNotes/UI/NotePageRenderer.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<RowDefinition />
3434
</Grid.RowDefinitions>
3535
<TextBox
36+
Name="TitleTextBox"
3637
VerticalAlignment="Center"
3738
BorderThickness="0"
3839
FontSize="16"
@@ -43,7 +44,6 @@
4344
Grid.Row="1"
4445
Name="NoteItemsListView"
4546
ItemTemplateSelector="{StaticResource NoteItemDataTemplateSelector}"
46-
ItemsSource="{x:Bind NotePage.NoteItems, Mode=OneWay}"
4747
SelectionMode="None">
4848
<ListView.ItemContainerStyle>
4949
<Style TargetType="ListViewItem">

ContosoNotes/UI/NotePageRenderer.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Windows.System;
88
using Windows.UI.Xaml;
99
using Windows.UI.Xaml.Controls;
10+
using Windows.UI.Xaml.Data;
1011
using Windows.UI.Xaml.Input;
1112

1213
namespace ContosoNotes.UI
@@ -28,6 +29,14 @@ private static void OnNotePageChanged(DependencyObject d, DependencyPropertyChan
2829
if (e.NewValue is NotePageModel newNotePageModel)
2930
{
3031
newNotePageModel.NoteItems.CollectionChanged += notePageRenderer.OnNoteItemsCollectionChanged;
32+
notePageRenderer.NoteItemsListView.ItemsSource = newNotePageModel.NoteItems;
33+
34+
notePageRenderer.TitleTextBox.SetBinding(TextBox.TextProperty, new Binding()
35+
{
36+
Source = newNotePageModel,
37+
Path = new PropertyPath(nameof(NotePageModel.PageTitle)),
38+
Mode = BindingMode.TwoWay
39+
});
3140
}
3241
}
3342
}

ContosoNotes/Views/MainPage.xaml

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
x:Class="ContosoNotes.Views.MainPage"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
65
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
76
xmlns:graphcontrols="using:CommunityToolkit.Uwp.Graph.Controls"
87
xmlns:local="using:ContosoNotes.Views"
98
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
109
xmlns:models="using:ContosoNotes.Models"
11-
xmlns:ui="using:ContosoNotes.UI" xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
10+
xmlns:ui="using:ContosoNotes.UI"
11+
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
1212
d:DataContext="{d:DesignInstance Type=local:MainViewModel}"
1313
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
1414
mc:Ignorable="d">
1515

1616
<Page.Resources>
1717
<x:Boolean x:Key="Boolean_True">True</x:Boolean>
1818
<x:Boolean x:Key="Boolean_False">False</x:Boolean>
19-
19+
2020
<ui:LastSyncDateTimeConverter x:Key="LastSyncDateTimeConverter" />
2121

2222
<Style x:Key="CustomButtonStyle" TargetType="Button">
@@ -64,18 +64,19 @@
6464
</controls:SwitchPresenter>
6565
</Button>
6666

67-
6867
<StackPanel Grid.Column="1" Orientation="Horizontal">
6968
<!--<Button Style="{StaticResource CustomButtonStyle}">
7069
<Image Source="ms-appx:///Assets/Translate.png" />
7170
</Button>
7271
<Button Style="{StaticResource CustomButtonStyle}">
7372
<Image Source="ms-appx:///Assets/Font.png" />
74-
</Button>
75-
<Button Style="{StaticResource CustomButtonStyle}">
73+
</Button>-->
74+
<Button
75+
Command="{x:Bind ViewModel.DeleteCurrentNotePageCommand}"
76+
Style="{StaticResource CustomButtonStyle}">
7677
<Image Source="ms-appx:///Assets/Discard.png" />
7778
</Button>
78-
<Button Style="{StaticResource CustomButtonStyle}">
79+
<!--<Button Style="{StaticResource CustomButtonStyle}">
7980
<Image Source="ms-appx:///Assets/Attach.png" />
8081
</Button>
8182
<Button Style="{StaticResource CustomButtonStyle}">
@@ -103,7 +104,7 @@
103104
<!-- Notes list -->
104105
<Grid
105106
Grid.Row="1"
106-
Padding="20,0,0,12"
107+
Padding="24,0,0,24"
107108
BorderBrush="#717171"
108109
BorderThickness="0,0,1,0"
109110
Visibility="{x:Bind ViewModel.IsPaneOpen, Mode=OneWay}"
@@ -115,7 +116,7 @@
115116

116117
<!-- List of notes -->
117118
<ListView
118-
Margin="0, 0, 4, 0"
119+
SelectedIndex="{x:Bind ViewModel.CurrentNotesListItemIndex, Mode=TwoWay}"
119120
ItemsSource="{x:Bind ViewModel.NotesList.Items, Mode=OneWay}">
120121
<ListView.ItemTemplate>
121122
<DataTemplate x:DataType="models:NotesListItemModel">
@@ -131,9 +132,17 @@
131132

132133
<!-- Notes list footer panel -->
133134
<StackPanel Grid.Row="1" Orientation="Horizontal">
134-
<!--<Button Style="{StaticResource CustomButtonStyle}">
135-
<Image Source="ms-appx:///Assets/NewNote.png" />
136-
</Button>-->
135+
<controls:SwitchPresenter
136+
VerticalAlignment="Bottom"
137+
Value="{x:Bind ViewModel.IsPaneOpen, Mode=OneWay}">
138+
<controls:Case Value="{StaticResource Boolean_True}">
139+
<Button
140+
Style="{StaticResource CustomButtonStyle}"
141+
Command="{x:Bind ViewModel.CreateNotePageCommand}">
142+
<Image Source="ms-appx:///Assets/NewNote.png" />
143+
</Button>
144+
</controls:Case>
145+
</controls:SwitchPresenter>
137146
</StackPanel>
138147
</Grid>
139148

@@ -160,10 +169,18 @@
160169
</Grid.ColumnDefinitions>
161170

162171
<StackPanel Orientation="Horizontal">
163-
<!--<Button Style="{StaticResource CustomButtonStyle}" Visibility="{x:Bind ViewModel.IsPaneOpen, Converter={StaticResource InverseBoolToVisibilityConverter}, Mode=OneWay}">
164-
<Image Source="ms-appx:///Assets/NewNote.png" />
165-
</Button>
166-
<Button Style="{StaticResource CustomButtonStyle}">
172+
<controls:SwitchPresenter
173+
VerticalAlignment="Bottom"
174+
Value="{x:Bind ViewModel.IsPaneOpen, Mode=OneWay}">
175+
<controls:Case Value="{StaticResource Boolean_False}">
176+
<Button
177+
Style="{StaticResource CustomButtonStyle}"
178+
Command="{x:Bind ViewModel.CreateNotePageCommand}">
179+
<Image Source="ms-appx:///Assets/NewNote.png" />
180+
</Button>
181+
</controls:Case>
182+
</controls:SwitchPresenter>
183+
<!--<Button Style="{StaticResource CustomButtonStyle}">
167184
<Image Source="ms-appx:///Assets/Undo.png" />
168185
</Button>
169186
<Button Style="{StaticResource CustomButtonStyle}">

0 commit comments

Comments
 (0)