Skip to content

Commit ebcdf29

Browse files
Merge branch 'main' into fix_tcb_winui2.6
2 parents a66b6d0 + 935875a commit ebcdf29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1396
-415
lines changed

.gitattributes

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#
1818
# Merging from the command prompt will add diff markers to the files if there
1919
# are conflicts (Merging from VS is not affected by the settings below, in VS
20-
# the diff markers are never inserted). Diff markers may cause the following
20+
# the diff markers are never inserted). Diff markers may cause the following
2121
# file extensions to fail to load in VS. An alternative would be to treat
2222
# these files as binary and thus will always conflict and require user
2323
# intervention with every merge. To do so, just uncomment the entries below
@@ -46,9 +46,9 @@
4646

4747
###############################################################################
4848
# diff behavior for common document formats
49-
#
49+
#
5050
# Convert binary document formats to text before diffing them. This feature
51-
# is only available from the command line. Turn it on by uncommenting the
51+
# is only available from the command line. Turn it on by uncommenting the
5252
# entries below.
5353
###############################################################################
5454
#*.doc diff=astextplain

.runsettings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<RunSettings>
22
<MSTest>
3-
<MaxCpuCount>0</MaxCpuCount>
3+
<MaxCpuCount>0</MaxCpuCount>
44
<Parallelize>
55
<Workers>0</Workers>
66
<Scope>ClassLevel</Scope>

Microsoft.Toolkit.Uwp.SampleApp/Controls/SampleAppMarkdownRenderer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8+
using Microsoft.Toolkit.Helpers;
89
using Microsoft.Toolkit.Parsers.Markdown;
910
using Microsoft.Toolkit.Parsers.Markdown.Blocks;
1011
using Microsoft.Toolkit.Parsers.Markdown.Inlines;
@@ -407,19 +408,19 @@ public string DesiredLang
407408
{
408409
get
409410
{
410-
return storage.Read<string>(DesiredLangKey);
411+
return settingsStorage.Read<string>(DesiredLangKey);
411412
}
412413

413414
set
414415
{
415-
storage.Save(DesiredLangKey, value);
416+
settingsStorage.Save(DesiredLangKey, value);
416417
}
417418
}
418419

419420
/// <summary>
420-
/// The Local Storage Helper.
421+
/// The local app data storage helper for storing settings.
421422
/// </summary>
422-
private LocalObjectStorageHelper storage = new LocalObjectStorageHelper(new SystemSerializer());
423+
private readonly ApplicationDataStorageHelper settingsStorage = ApplicationDataStorageHelper.GetCurrent();
423424

424425
/// <summary>
425426
/// DocFX note types and styling info, keyed by identifier.

Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// TODO Reintroduce graph controls
2121
// using Microsoft.Toolkit.Graph.Converters;
2222
// using Microsoft.Toolkit.Graph.Providers;
23+
using Microsoft.Toolkit.Helpers;
2324
using Microsoft.Toolkit.Uwp.Helpers;
2425
using Microsoft.Toolkit.Uwp.Input.GazeInteraction;
2526
using Microsoft.Toolkit.Uwp.SampleApp.Models;
@@ -45,7 +46,7 @@ public class Sample
4546

4647
public static async void EnsureCacheLatest()
4748
{
48-
var settingsStorage = new LocalObjectStorageHelper(new SystemSerializer());
49+
var settingsStorage = ApplicationDataStorageHelper.GetCurrent();
4950

5051
var onlineDocsSHA = await GetDocsSHA();
5152
var cacheSHA = settingsStorage.Read<string>(_cacheSHAKey);

Microsoft.Toolkit.Uwp.SampleApp/Models/Samples.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Text.Json;
1010
using System.Threading;
1111
using System.Threading.Tasks;
12+
using Microsoft.Toolkit.Helpers;
1213
using Microsoft.Toolkit.Uwp.Helpers;
1314

1415
namespace Microsoft.Toolkit.Uwp.SampleApp
@@ -21,7 +22,7 @@ public static class Samples
2122
private static SemaphoreSlim _semaphore = new SemaphoreSlim(1);
2223

2324
private static LinkedList<Sample> _recentSamples;
24-
private static LocalObjectStorageHelper _localObjectStorageHelper = new LocalObjectStorageHelper(new SystemSerializer());
25+
private static ApplicationDataStorageHelper _settingsStorage = ApplicationDataStorageHelper.GetCurrent();
2526

2627
public static async Task<SampleCategory> GetCategoryBySample(Sample sample)
2728
{
@@ -98,7 +99,7 @@ public static async Task<LinkedList<Sample>> GetRecentSamples()
9899
if (_recentSamples == null)
99100
{
100101
_recentSamples = new LinkedList<Sample>();
101-
var savedSamples = _localObjectStorageHelper.Read<string>(_recentSamplesStorageKey);
102+
var savedSamples = _settingsStorage.Read<string>(_recentSamplesStorageKey);
102103

103104
if (savedSamples != null)
104105
{
@@ -144,7 +145,7 @@ private static void SaveRecentSamples()
144145
}
145146

146147
var str = string.Join(";", _recentSamples.Take(10).Select(s => s.Name).ToArray());
147-
_localObjectStorageHelper.Save<string>(_recentSamplesStorageKey, str);
148+
_settingsStorage.Save<string>(_recentSamplesStorageKey, str);
148149
}
149150
}
150151
}

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListDetailsView/ListDetailsView.bind

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,20 @@
7474
</controls:ListDetailsView.NoSelectionContentTemplate>
7575
<controls:ListDetailsView.ListCommandBar>
7676
<CommandBar>
77+
<!-- Button functionality to be implemented by developer -->
7778
<AppBarButton Icon="Back" Label="Back"/>
7879
<AppBarButton Icon="Forward" Label="Forward"/>
79-
80-
<CommandBar.Content>
81-
<TextBlock Margin="12,14">
82-
<Run Text="{Binding Emails.Count}" />
83-
<Run Text="Items" />
84-
</TextBlock>
85-
</CommandBar.Content>
86-
</CommandBar>
80+
<CommandBar.Content>
81+
<TextBlock Margin="12,14">
82+
<Run Text="{Binding Emails.Count}" />
83+
<Run Text="Items" />
84+
</TextBlock>
85+
</CommandBar.Content>
86+
</CommandBar>
8787
</controls:ListDetailsView.ListCommandBar>
8888
<controls:ListDetailsView.DetailsCommandBar>
8989
<CommandBar>
90+
<!-- Button functionality to be implemented by developer -->
9091
<AppBarButton Icon="MailReply" Label="Reply" />
9192
<AppBarButton Icon="MailReplyAll" Label="Reply All" />
9293
<AppBarButton Icon="MailForward" Label="Forward" />
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
var localObjectStorageHelper = new LocalObjectStorageHelper();
2-
var roamingObjectStorageHelper = new RoamingObjectStorageHelper();
1+
ApplicationDataStorageHelper appDataStorageHelper = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer());
32

43
// Read and Save with simple objects
54
string keySimpleObject = "simple";
6-
string result = localObjectStorageHelper.Read<string>(keySimpleObject);
7-
localObjectStorageHelper.Save(keySimpleObject, 47);
5+
string result = appDataStorageHelper.Read<string>(keySimpleObject);
6+
appDataStorageHelper.Save(keySimpleObject, 47);
87

98
// Read and Save with complex/large objects
10-
string keyLargeObject = "large";
11-
var result = localObjectStorageHelper.ReadFileAsync<MyLargeObject>(keyLargeObject);
9+
string complexObjectKey = "complexObject";
10+
var complexObject = await appDataStorageHelper.ReadFileAsync<MyLargeObject>(complexObjectKey);
1211

13-
var o = new MyLargeObject
12+
var myComplexObject = new MyComplexObject()
1413
{
1514
...
1615
};
17-
localObjectStorageHelper.SaveFileAsync(keySimpleObject, o);
16+
await appDataStorageHelper.SaveFileAsync(complexObjectKey, myComplexObject);
1817

1918
// Complex object
20-
public class MyLargeObject
19+
public class MyComplexObject
2120
{
2221
public string MyContent { get; set; }
2322
public List<string> MyContents { get; set; }
24-
public List<MyLargeObject> MyObjects { get; set; }
23+
public List<MyComplexObject> MyObjects { get; set; }
2524
}

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Object Storage/ObjectStoragePage.xaml.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using Microsoft.Toolkit.Helpers;
56
using Microsoft.Toolkit.Uwp.Helpers;
67
using Windows.UI.Xaml;
78

89
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
910
{
1011
public sealed partial class ObjectStoragePage
1112
{
12-
private readonly IObjectStorageHelper localStorageHelper = new LocalObjectStorageHelper(new SystemSerializer());
13+
private readonly ApplicationDataStorageHelper _settingsStorage = ApplicationDataStorageHelper.GetCurrent();
1314

1415
public ObjectStoragePage()
1516
{
@@ -24,9 +25,9 @@ private void ReadButton_Click(object sender, RoutedEventArgs e)
2425
}
2526

2627
// Read from local storage
27-
if (localStorageHelper.KeyExists(KeyTextBox.Text))
28+
if (_settingsStorage.KeyExists(KeyTextBox.Text))
2829
{
29-
ContentTextBox.Text = localStorageHelper.Read<string>(KeyTextBox.Text);
30+
ContentTextBox.Text = _settingsStorage.Read<string>(KeyTextBox.Text);
3031
}
3132
}
3233

@@ -43,7 +44,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
4344
}
4445

4546
// Save into local storage
46-
localStorageHelper.Save(KeyTextBox.Text, ContentTextBox.Text);
47+
_settingsStorage.Save(KeyTextBox.Text, ContentTextBox.Text);
4748
}
4849
}
4950
}

Microsoft.Toolkit.Uwp.UI.Controls.Layout/ListDetailsView/ListDetailsView.cs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Windows.UI.Xaml.Controls;
1111
using Windows.UI.Xaml.Input;
1212
using Windows.UI.Xaml.Navigation;
13+
using NavigationView = Microsoft.UI.Xaml.Controls;
1314

1415
namespace Microsoft.Toolkit.Uwp.UI.Controls
1516
{
@@ -42,12 +43,11 @@ public partial class ListDetailsView : ItemsControl
4243
private AppViewBackButtonVisibility? _previousSystemBackButtonVisibility;
4344
private bool _previousNavigationViewBackEnabled;
4445

45-
// Int used because the underlying type is an enum, but we don't have access to the enum
46-
private int _previousNavigationViewBackVisibilty;
46+
private NavigationView.NavigationViewBackButtonVisible _previousNavigationViewBackVisibilty;
47+
private NavigationView.NavigationView _navigationView;
4748
private ContentPresenter _detailsPresenter;
4849
private VisualStateGroup _selectionStateGroup;
4950
private Button _inlineBackButton;
50-
private object _navigationView;
5151
private Frame _frame;
5252

5353
/// <summary>
@@ -199,7 +199,7 @@ private void OnLoaded(object sender, RoutedEventArgs e)
199199
_frame.Navigating -= OnFrameNavigating;
200200
}
201201

202-
_navigationView = this.FindAscendants().FirstOrDefault(p => p.GetType().FullName == "Microsoft.UI.Xaml.Controls.NavigationView");
202+
_navigationView = this.FindAscendant<NavigationView.NavigationView>();
203203
_frame = this.FindAscendant<Frame>();
204204
if (_frame != null)
205205
{
@@ -328,8 +328,6 @@ private void UpdateView(bool animate)
328328
/// </summary>
329329
private void SetBackButtonVisibility(ListDetailsViewState? previousState = null)
330330
{
331-
const int backButtonVisible = 1;
332-
333331
if (DesignMode.DesignModeEnabled)
334332
{
335333
return;
@@ -358,7 +356,7 @@ private void SetBackButtonVisibility(ListDetailsViewState? previousState = null)
358356
}
359357
else
360358
{
361-
SetNavigationViewBackButtonState(backButtonVisible, true);
359+
SetNavigationViewBackButtonState(NavigationView.NavigationViewBackButtonVisible.Visible, true);
362360
}
363361
}
364362
else if (BackButtonBehavior != BackButtonBehavior.Manual)
@@ -441,27 +439,18 @@ private void SetVisualState(bool animate)
441439
VisualStateManager.GoToState(this, SelectedItem == null ? noSelectionState : hasSelectionState, animate);
442440
}
443441

444-
private void SetNavigationViewBackButtonState(int visible, bool enabled)
442+
private void SetNavigationViewBackButtonState(NavigationView.NavigationViewBackButtonVisible visibility, bool enabled)
445443
{
446444
if (_navigationView == null)
447445
{
448446
return;
449447
}
450448

451-
var navType = _navigationView.GetType();
452-
var visibleProperty = navType.GetProperty("IsBackButtonVisible");
453-
if (visibleProperty != null)
454-
{
455-
_previousNavigationViewBackVisibilty = (int)visibleProperty.GetValue(_navigationView);
456-
visibleProperty.SetValue(_navigationView, visible);
457-
}
449+
_previousNavigationViewBackVisibilty = _navigationView.IsBackButtonVisible;
450+
_navigationView.IsBackButtonVisible = visibility;
458451

459-
var enabledProperty = navType.GetProperty("IsBackEnabled");
460-
if (enabledProperty != null)
461-
{
462-
_previousNavigationViewBackEnabled = (bool)enabledProperty.GetValue(_navigationView);
463-
enabledProperty.SetValue(_navigationView, enabled);
464-
}
452+
_previousNavigationViewBackEnabled = _navigationView.IsBackEnabled;
453+
_navigationView.IsBackEnabled = enabled;
465454
}
466455

467456
private void SetDetailsContent()
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Threading.Tasks;
8+
using Microsoft.Toolkit.Helpers;
9+
using Windows.Storage;
10+
11+
namespace Microsoft.Toolkit.Uwp.Helpers
12+
{
13+
/// <summary>
14+
/// An extension of ApplicationDataStorageHelper with additional features for interop with the LocalCacheFolder.
15+
/// </summary>
16+
public partial class ApplicationDataStorageHelper
17+
{
18+
/// <summary>
19+
/// Gets the local cache folder.
20+
/// </summary>
21+
public StorageFolder CacheFolder => AppData.LocalCacheFolder;
22+
23+
/// <summary>
24+
/// Retrieves an object from a file in the LocalCacheFolder.
25+
/// </summary>
26+
/// <typeparam name="T">Type of object retrieved.</typeparam>
27+
/// <param name="filePath">Path to the file that contains the object.</param>
28+
/// <param name="default">Default value of the object.</param>
29+
/// <returns>Waiting task until completion with the object in the file.</returns>
30+
public Task<T> ReadCacheFileAsync<T>(string filePath, T @default = default)
31+
{
32+
return ReadFileAsync<T>(CacheFolder, filePath, @default);
33+
}
34+
35+
/// <summary>
36+
/// Retrieves the listings for a folder and the item types in the LocalCacheFolder.
37+
/// </summary>
38+
/// <param name="folderPath">The path to the target folder.</param>
39+
/// <returns>A list of file types and names in the target folder.</returns>
40+
public Task<IEnumerable<(DirectoryItemType ItemType, string Name)>> ReadCacheFolderAsync(string folderPath)
41+
{
42+
return ReadFolderAsync(CacheFolder, folderPath);
43+
}
44+
45+
/// <summary>
46+
/// Saves an object inside a file in the LocalCacheFolder.
47+
/// </summary>
48+
/// <typeparam name="T">Type of object saved.</typeparam>
49+
/// <param name="filePath">Path to the file that will contain the object.</param>
50+
/// <param name="value">Object to save.</param>
51+
/// <returns>Waiting task until completion.</returns>
52+
public Task CreateCacheFileAsync<T>(string filePath, T value)
53+
{
54+
return SaveFileAsync<T>(CacheFolder, filePath, value);
55+
}
56+
57+
/// <summary>
58+
/// Ensure a folder exists at the folder path specified in the LocalCacheFolder.
59+
/// </summary>
60+
/// <param name="folderPath">The path and name of the target folder.</param>
61+
/// <returns>Waiting task until completion.</returns>
62+
public Task CreateCacheFolderAsync(string folderPath)
63+
{
64+
return CreateFolderAsync(CacheFolder, folderPath);
65+
}
66+
67+
/// <summary>
68+
/// Deletes a file or folder item in the LocalCacheFolder.
69+
/// </summary>
70+
/// <param name="itemPath">The path to the item for deletion.</param>
71+
/// <returns>Waiting task until completion.</returns>
72+
public Task DeleteCacheItemAsync(string itemPath)
73+
{
74+
return DeleteItemAsync(CacheFolder, itemPath);
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)