Skip to content

Commit e8b6859

Browse files
committed
chore: update and add Settings for samples
1 parent 0501f30 commit e8b6859

21 files changed

+470
-176
lines changed

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
},
77
"files.associations": {
88
"global.json": "jsonc"
9-
}
10-
}
9+
},
10+
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The samples in this Repository are meant to help other Developers, independent to their pre-knowledge, get an Idea of how to use the shown things.
44

55
> [!TIP]
6-
> Check out the [Documentation](./doc/), for more a more detailed List and future coming Guides and Explanations.
6+
> Check out the [Documentation](./doc/articles/introduction.md), for more a more detailed List and future coming Guides and Explanations.
77
88
## Table of Contents
99

@@ -20,6 +20,7 @@ The samples in this Repository are meant to help other Developers, independent t
2020
## Mvux Gallery
2121

2222
Following list provides you a quick Overview, what you can find in the [Mvux Gallery](./src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery) App.
23+
The depending Documentation you can find [here](./doc/articles/MvuxGallery/Overview.md)
2324

2425
### Controls to be explored in this App
2526

cSpell.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// cSpell configuration file
3+
"version": "0.2",
4+
"language": "en",
5+
"words": [
6+
// Add custom words here
7+
"DevTKSS",
8+
"Listboard"
9+
],
10+
"ignoreWords": [],
11+
"ignorePaths": [
12+
// Add file paths to ignore here
13+
"node_modules/**",
14+
"dist/**",
15+
"src/*"
16+
]
17+
}

doc/articles/MvuxGallery/Overview.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ uid: DevTKSS.Uno.SampleApps.MvuxGallery.Overview
44

55
## Mvux Gallery
66

7-
At the [Mvux Gallery](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery) you can explore the following features:
7+
At the [Mvux Gallery](../../../src/DevTKSS.Uno.Samples.MvuxGallery/) you can explore the following features:
88

99
### Controls
1010

11-
- [FeedView + ListView](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/ListboardPage.xaml)
12-
- [DataTemplate centralized Resource Definition](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Styles/Generic.xaml)
13-
- [Card](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/SimpleCardsPage.xaml)
14-
- [`ItemOverlayTemplate` DataTemplate](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Styles/Generic.xaml#L92-L123) (*Layout replicated from WinUI 3 Gallery*)
15-
- [Counter](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/CounterPage.xaml)
16-
- [Settings](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/SettingsPage.xaml)
17-
- [FeedView + GridView](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/DashboardPage.xaml)
18-
- [FeedView + ListView](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/ListboardPage.xaml)
19-
- [DataTemplate centralized Resource Definition](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Styles/Generic.xaml)
20-
- [Card](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/SimpleCardsPage.xaml)
21-
- [`ItemOverlayTemplate` DataTemplate](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Styles/Generic.xaml#L92-L123) (*Layout replicated from WinUI 3 Gallery*)
11+
- [FeedView + ListView](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/ListboardPage.xaml)
12+
- [DataTemplate centralized Resource Definition](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Styles/Generic.xaml)
13+
- [Card](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/SimpleCardsPage.xaml)
14+
- [`ItemOverlayTemplate` DataTemplate](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Styles/Generic.xaml) (*Layout replicated from WinUI 3 Gallery*)
15+
- [Counter](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/CounterPage.xaml)
16+
- [Settings](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/SettingsPage.xaml)
17+
- [FeedView + GridView](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/DashboardPage.xaml)
18+
- [FeedView + ListView](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/ListboardPage.xaml)
19+
- [DataTemplate centralized Resource Definition](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Styles/Generic.xaml)
20+
- [Card](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/SimpleCardsPage.xaml)
21+
- [`ItemOverlayTemplate` DataTemplate](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Styles/Generic.xaml) (*Layout replicated from WinUI 3 Gallery*)
2222

2323
### Uno.Extensions
2424

@@ -33,61 +33,61 @@ At the [Mvux Gallery](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxG
3333
- Navigation
3434
- via Xaml
3535
- NavigationView
36-
- [MainPage.xaml](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/MainPage.xaml#L1-L50))
36+
- [MainPage.xaml](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/Views/MainPage.xaml)
3737
- Via Model
3838
- (planned)
3939

4040
- Hosting
41-
- [App.xaml.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/App.xaml.cs#L21-L91)
41+
- [App.xaml.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/App.xaml.cs)
4242

4343
- DependencyInjection
4444
- Service Registration
45-
- [App.xaml.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/App.xaml.cs#L69-L74)
45+
- [App.xaml.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/App.xaml.cs)
4646
- Service Definition
47-
- [CodeSampleService.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleService.cs)
48-
- [ICodeSampleService.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/ICodeSampleService.cs)
47+
- [CodeSampleService.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleService.cs)
48+
- [ICodeSampleService.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/ICodeSampleService.cs)
4949
- Data Model Definition
50-
- [SampleCode.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/SampleCode.cs)
51-
- [CodeSampleOption.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleOption.cs)
52-
- [CodeSampleOptionsConfiguration.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleOptionsConfiguration.cs)
50+
- [SampleCode.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/SampleCode.cs)
51+
- [CodeSampleOption.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleOption.cs)
52+
- [CodeSampleOptionsConfiguration.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleOptionsConfiguration.cs)
5353

5454
- Serialization
5555
- JsonSerializerContext of each DataModel
56-
- [CodeSampleOptionsContext](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleOptions.cs#L8-L11)
57-
- [CodeSampleOptionsConfigurationContext](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleOptionsConfiguration.cs#L6-L9)
56+
- [CodeSampleOptionsContext](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleOptions.cs)
57+
- [CodeSampleOptionsConfigurationContext](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleOptionsConfiguration.cs)
5858

5959
- Configuration
6060
- Data for Serialization
61-
- [appsettings.json](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/appsettings.json)
61+
- [appsettings.json](../../../src/DevTKSS.Uno.Samples.MvuxGallery/appsettings.json)
6262

6363
- Storage
6464
- Via Model
65-
- [DashboardModel.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/ViewModels/DashboardModel.cs#L55-L141)
65+
- [DashboardModel.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/ViewModels/DashboardModel.cs)
6666
- Via Service
67-
- [CodeSampleService.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleService.cs)
67+
- [CodeSampleService.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleService.cs)
6868
- Via StorageExtension
6969
- Currently in private preview package
7070
- Via Uno.Extensions.Storage.IStorage Interface extension
7171
- added as PR to Uno.Extensions [#2734](https://github.com/unoplatform/uno.extensions/pull/2734)
7272

7373
- Localization
7474
- **IStringLocalizer**
75-
- Resources Dictionarys
76-
- [en](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Strings/en/Resources.resw)
77-
- [de](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Strings/en/Resources.resw)
75+
- Resources Dictionaries
76+
- [en](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Strings/en/)
77+
- [de](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Strings/de/)
7878
- Binding current value in `IState<string>` and to corresponding View
79-
- [DashboardModel.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/ViewModels/DashboardModel.cs#L31)
80-
- [ListboardModel.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/ViewModels/ListboardModel.cs#L33)
81-
- [MainModel.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Presentation/ViewModels/MainModel.cs#L21)
79+
- [DashboardModel.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/ViewModels/DashboardModel.cs)
80+
- [ListboardModel.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/ViewModels/ListboardModel.cs)
81+
- [MainModel.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Presentation/ViewModels/MainModel.cs)
8282
- CounterModel.cs
8383
- Requesting localized Items via FeedView
8484
- Service Definition
85-
- [GalleryImageService.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/GalleryImages/GalleryImageService.cs#L34-L66)
86-
- [IGalleryImageService.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/GalleryImages/IGalleryImageService.cs#L6)
85+
- [GalleryImageService.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/GalleryImages/GalleryImageService.cs)
86+
- [IGalleryImageService.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/GalleryImages/IGalleryImageService.cs)
8787
- Data Model Definition
88-
- [GalleryImageModel.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/GalleryImages/GalleryImageModel.cs)
88+
- [GalleryImageModel.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/GalleryImages/GalleryImageModel.cs)
8989
- **ILocalizationService**
90-
- Requesing current culture
91-
- [GalleryImageService.cs](../../../src/DevTKSS.Uno.Samples/DevTKSS.Uno.Samples.MvuxGallery/Models/GalleryImages/GalleryImageService.cs#L19-L30)
92-
- Switching culture
93-
- (planned)
90+
- Requesting current culture
91+
- [GalleryImageService.cs](../../../src/DevTKSS.Uno.Samples.MvuxGallery/Models/GalleryImages/GalleryImageService.cs)
92+
- Switching culture
93+
- (planned)

doc/docfx.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"**/*.{md,yml}"
2121
],
2222
"exclude": [
23-
"_site/**"
23+
"_site/**",
24+
"api/Uno.Resizetizer*.yml"
2425
]
2526
}
2627
],
@@ -52,4 +53,4 @@
5253
"pdf": false
5354
}
5455
}
55-
}
56+
}

src/DevTKSS.Uno.Samples.MvuxGallery/App.xaml.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ protected async override void OnLaunched(LaunchActivatedEventArgs args)
6262
configBuilder
6363
.EmbeddedSource<App>()
6464
.Section<AppConfig>()
65-
.Section<CodeSampleOptionsConfiguration>()
65+
66+
.EmbeddedSource<App>("sampledata")
6667
.Section<CodeSampleOptionsConfiguration>("DashboardSampleConfiguration")
6768
.Section<CodeSampleOptionsConfiguration>("MainSampleConfiguration")
6869
.Section<CodeSampleOptionsConfiguration>("ListboardSampleConfiguration")
70+
.Section<CodeSampleOptionsConfiguration>("CounterSampleConfiguration")
71+
.Section<CodeSampleOptionsConfiguration>("SimpleCardsSampleConfiguration")
6972
)
7073
// Enable localization (see appsettings.json for supported languages)
7174
.UseLocalization()
@@ -89,7 +92,7 @@ protected async override void OnLaunched(LaunchActivatedEventArgs args)
8992
MainWindow.UseStudio();
9093
#endif
9194
MainWindow.SetWindowIcon();
92-
95+
9396
Host = await builder.NavigateAsync<Shell>();
9497
}
9598

@@ -113,10 +116,10 @@ private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
113116
new ("Dashboard", View: views.FindByViewModel<DashboardModel>(),IsDefault: true),
114117
new ("Listboard", View: views.FindByViewModel<ListboardModel>()),
115118
new ("Counter", View: views.FindByViewModel<CounterModel>()),
116-
119+
117120
]
118121
),
119-
122+
120123
]
121124
)
122125
);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
namespace DevTKSS.Uno.Samples.MvuxGallery.Models.CodeSamples;
2+
3+
public record CodeSampleOptionsConfiguration
4+
{
5+
public Dictionary<string, CodeSampleOption> Samples { get; init; } = new();
6+
}
7+
8+
public record CodeSampleOption
9+
{
10+
public string Description { get; init; } = string.Empty;
11+
public string FilePath { get; init; } = string.Empty;
12+
public List<(int Start, int End)> LineRanges { get; init; } = [];
13+
}
14+
15+
namespace DevTKSS.Uno.Samples.MvuxGallery.Models.CodeSamples;
16+
17+
[JsonSerializable(typeof(CodeSampleOptionsConfiguration))]
18+
public partial class CodeSampleOptionsConfigurationContext : JsonSerializerContext
19+
{
20+
}
21+
22+
[JsonSerializable(typeof(CodeSampleOption))]
23+
public partial class CodeSampleOptionContext : JsonSerializerContext
24+
{
25+
}
26+
27+
{
28+
"ListboardSampleConfiguration": {
29+
"FeedView + ListView XAML": {
30+
"Description": "",
31+
"FilePath": "Assets/Samples/FeedView-ListView-Sample.xaml.txt",
32+
"LineRanges": []
33+
},
34+
"Use Service to load Data from Storage": {
35+
"Description": "This sample shows how to use a service to load data from storage. The service is registered in the DI container and can be injected into the view model.",
36+
"FilePath": "Assets/Samples/Listboard-SampleViaService.cs.txt",
37+
"LineRanges": []
38+
},
39+
"DI Storage handling Service": {
40+
"FilePath": "Assets/Samples/Listboard-StorageService.cs.txt",
41+
"LineRanges": []
42+
},
43+
"Settings DataModel Definition": {
44+
"Description": "While DataModels used to load Data via IOptions can not be fully immutable, using init instead of set allows us to set the properties only once, when the object is created.",
45+
"FilePath": "Assets/Samples/CodeSample-Definition.cs.txt",
46+
"LineRanges": [ 1, 13 ]
47+
},
48+
"Settings DataModel JsonContext": {
49+
"Description": "Define the JsonSerializerContext to load the code sample options configuration from the appsettings.json file.",
50+
"FilePath": "Assets/Samples/CodeSample-Definition.cs.txt",
51+
"LineRanges": [ 15, 25 ]
52+
},
53+
"Settings Data in appsettings": {
54+
"Description": "Settings to find storage Data, can easily be stored in appsettings.json, since we can update them via IWritableOptions.",
55+
"FilePath": "Assets/Samples/CodeSample-Definition.cs.txt",
56+
"LineRanges": []
57+
},
58+
"XAML DataTemplate": {
59+
"Description": "The DataTemplate is used to define how the data is displayed in the ListView. The DataTemplate is showing a Card Control from Uno.Toolkit.UI and is definied in a ResourcesDictionary loaded via MergedResourcesDictionaries.",
60+
"FilePath": "Assets/Samples/Card-GalleryImage.DataTemplate.xaml.txt",
61+
"LineRanges": []
62+
},
63+
},
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
namespace DevTKSS.Uno.Samples.MvuxGallery.Models.CodeSamples;
2+
3+
4+
5+
public record CodeSampleService : ICodeSampleService
6+
{
7+
public CodeSampleService(
8+
IOptions<CodeSampleOptionsConfiguration> options,
9+
ILogger<CodeSampleService> logger,
10+
IStorage storage)
11+
{
12+
_options = options.Value;
13+
_logger = logger;
14+
_storage = storage;
15+
}
16+
17+
private readonly IStorage _storage;
18+
private readonly ILogger<CodeSampleService> _logger;
19+
private readonly CodeSampleOptionsConfiguration _options;
20+
21+
/// <summary>
22+
/// Get a static Collection of Values for <see cref="CodeSampleOptions"/>
23+
/// </summary>
24+
/// <param name="ct">
25+
/// A CancellationToken to make it compileable
26+
/// <remarks>
27+
/// since `ListFeed.Async` requires a CancellationToken even if Uno Documentation remarks this parameter to be optional.<br/>
28+
/// <see href="https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0411?f1url=%3FappId%3Droslyn%26k%3Dk(CS0411)">CS0411</see><br/>
29+
/// <br/>
30+
/// adding then the type string or IImmutableList<string> to the ListFeed like `ListFeed<string>.Async(...)`,
31+
/// or to the Async Extension itself like `ListFeed.Async<IImutableList<string>` results in a type mismatch.<br/>
32+
/// <see href="https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs1503?f1url=%3FappId%3Droslyn%26k%3Dk(CS1503)">CS1503</see>
33+
/// </remarks>
34+
/// <returns>An awaitable <see cref="ValueTask{TResult}"/> providing a <see cref="ImmutableList{T}"/> of <see langword="string"/> with the Sample Names to select from</returns>
35+
public async ValueTask<IImmutableList<string>> GetCodeSampleOptionsAsync(CancellationToken ct = default)
36+
{
37+
await Task.Delay(1);
38+
return _options.Samples.Keys.ToImmutableList();
39+
}
40+
41+
public async ValueTask<string> GetCodeSampleAsync(string sampleID, CancellationToken ct = default)
42+
{
43+
if (_options.Samples.TryGetValue(sampleID, out CodeSampleOption? sampleOption))
44+
{
45+
return await _storage.ReadLinesFromPackageFile(sampleOption.FilePath, sampleOption.LineRanges);
46+
}
47+
48+
_logger.LogWarning("Code sample with ID {sampleID} not found", sampleID);
49+
return string.Empty;
50+
}
51+
52+
}

0 commit comments

Comments
 (0)