Skip to content

Commit a792c0c

Browse files
committed
Demo App.xaml.cs more like Win Ui projects [skip ci]
1 parent ef6368a commit a792c0c

File tree

8 files changed

+191
-145
lines changed

8 files changed

+191
-145
lines changed

README.md

Lines changed: 85 additions & 61 deletions
Large diffs are not rendered by default.

src/Wpf.Ui.Demo/App.xaml.cs

Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -24,105 +24,107 @@ namespace Wpf.Ui.Demo;
2424
/// </summary>
2525
public partial class App
2626
{
27-
/// <summary>
28-
/// A program abstraction.
29-
/// </summary>
30-
private IHost _host;
27+
// The .NET Generic Host provides dependency injection, configuration, logging, and other services.
28+
// https://docs.microsoft.com/dotnet/core/extensions/generic-host
29+
// https://docs.microsoft.com/dotnet/core/extensions/dependency-injection
30+
// https://docs.microsoft.com/dotnet/core/extensions/configuration
31+
// https://docs.microsoft.com/dotnet/core/extensions/logging
32+
private static readonly IHost _host = Host
33+
.CreateDefaultBuilder()
34+
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); })
35+
.ConfigureServices((context, services) =>
36+
{
37+
// App Host
38+
services.AddHostedService<ApplicationHostService>();
3139

32-
/// <summary>
33-
/// Occurs when the application is loading.
34-
/// </summary>
35-
private async void OnStartup(object sender, StartupEventArgs e)
36-
{
37-
// For more information about .NET generic host see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-6.0
38-
_host = Host.CreateDefaultBuilder(e.Args)
39-
.ConfigureAppConfiguration(c =>
40-
{
41-
c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location));
42-
})
43-
.ConfigureServices(ConfigureServices)
44-
.Build();
40+
// Theme manipulation
41+
services.AddSingleton<IThemeService, ThemeService>();
4542

46-
await _host.StartAsync();
47-
}
43+
// Taskbar manipulation
44+
services.AddSingleton<ITaskBarService, TaskBarService>();
4845

49-
/// <summary>
50-
/// Configures the services for the application.
51-
/// </summary>
52-
private static void ConfigureServices(HostBuilderContext context, IServiceCollection services)
53-
{
54-
// App Host
55-
services.AddHostedService<ApplicationHostService>();
46+
// Snackbar service
47+
services.AddSingleton<ISnackbarService, SnackbarService>();
5648

57-
// Theme manipulation
58-
services.AddSingleton<IThemeService, ThemeService>();
49+
// Dialog service
50+
services.AddSingleton<IDialogService, DialogService>();
5951

60-
// Taskbar manipulation
61-
services.AddSingleton<ITaskBarService, TaskBarService>();
52+
// Tray icon
53+
// Just in case you wondering, it does not work yet
54+
// !! Experimental
55+
services.AddSingleton<INotifyIconService, NotifyIconService>();
6256

63-
//Snackbar service
64-
services.AddSingleton<ISnackbarService, SnackbarService>();
57+
// Page resolver service
58+
services.AddSingleton<IPageService, PageService>();
6559

66-
//Dialog service
67-
services.AddSingleton<IDialogService, DialogService>();
60+
// Page resolver service
61+
services.AddSingleton<ITestWindowService, TestWindowService>();
6862

69-
// Tray icon
70-
// Just in case you wondering, it does not work yet
71-
// !! Experimental
72-
services.AddSingleton<INotifyIconService, NotifyIconService>();
63+
// Service containing navigation, same as INavigationWindow... but without window
64+
services.AddSingleton<INavigationService, NavigationService>();
7365

74-
// Page resolver service
75-
services.AddSingleton<IPageService, PageService>();
66+
// Main window container with navigation
67+
services.AddScoped<INavigationWindow, Views.Container>();
68+
services.AddScoped<ContainerViewModel>();
7669

77-
// Page resolver service
78-
services.AddSingleton<ITestWindowService, TestWindowService>();
70+
// Views and ViewModels
71+
services.AddScoped<Views.Pages.Dashboard>();
7972

80-
// Service containing navigation, same as INavigationWindow... but without window
81-
services.AddSingleton<INavigationService, NavigationService>();
73+
services.AddScoped<Views.Pages.ExperimentalDashboard>();
74+
services.AddScoped<ExperimentalViewModel>();
8275

83-
// Main window container with navigation
84-
services.AddScoped<INavigationWindow, Views.Container>();
85-
services.AddScoped<ContainerViewModel>();
76+
services.AddScoped<Views.Pages.Controls>();
8677

87-
// Views and ViewModels
88-
services.AddScoped<Views.Pages.Dashboard>();
78+
services.AddScoped<Views.Pages.Menus>();
8979

90-
services.AddScoped<Views.Pages.ExperimentalDashboard>();
91-
services.AddScoped<ExperimentalViewModel>();
80+
services.AddScoped<Views.Pages.Colors>();
81+
services.AddScoped<ColorsViewModel>();
9282

93-
services.AddScoped<Views.Pages.Controls>();
83+
services.AddScoped<Views.Pages.Debug>();
84+
services.AddScoped<DebugViewModel>();
9485

95-
services.AddScoped<Views.Pages.Menus>();
86+
services.AddScoped<Views.Pages.Buttons>();
87+
services.AddScoped<ButtonsViewModel>();
9688

97-
services.AddScoped<Views.Pages.Colors>();
98-
services.AddScoped<ColorsViewModel>();
89+
services.AddScoped<Views.Pages.Data>();
90+
services.AddScoped<DataViewModel>();
9991

100-
services.AddScoped<Views.Pages.Debug>();
101-
services.AddScoped<DebugViewModel>();
92+
services.AddScoped<Views.Pages.Input>();
93+
services.AddScoped<InputViewModel>();
10294

103-
services.AddScoped<Views.Pages.Buttons>();
104-
services.AddScoped<ButtonsViewModel>();
95+
services.AddScoped<Views.Pages.Icons>();
96+
services.AddScoped<IconsViewModel>();
10597

106-
services.AddScoped<Views.Pages.Data>();
107-
services.AddScoped<DataViewModel>();
98+
// Test windows
99+
services.AddTransient<Views.Windows.TaskManagerWindow>();
100+
services.AddTransient<TaskManagerViewModel>();
108101

109-
services.AddScoped<Views.Pages.Input>();
110-
services.AddScoped<InputViewModel>();
102+
services.AddTransient<Views.Windows.EditorWindow>();
103+
services.AddTransient<Views.Windows.SettingsWindow>();
104+
services.AddTransient<Views.Windows.StoreWindow>();
105+
services.AddTransient<Views.Windows.ExperimentalWindow>();
111106

112-
services.AddScoped<Views.Pages.Icons>();
113-
services.AddScoped<IconsViewModel>();
107+
// Configuration
108+
services.Configure<AppConfig>(context.Configuration.GetSection(nameof(AppConfig)));
109+
}).Build();
114110

115-
// Test windows
116-
services.AddTransient<Views.Windows.TaskManagerWindow>();
117-
services.AddTransient<TaskManagerViewModel>();
118-
119-
services.AddTransient<Views.Windows.EditorWindow>();
120-
services.AddTransient<Views.Windows.SettingsWindow>();
121-
services.AddTransient<Views.Windows.StoreWindow>();
122-
services.AddTransient<Views.Windows.ExperimentalWindow>();
111+
/// <summary>
112+
/// Gets registered service.
113+
/// </summary>
114+
/// <typeparam name="T">Type of the service to get.</typeparam>
115+
/// <returns>Instance of the service or <see langword="null"/>.</returns>
116+
public static T GetService<T>()
117+
where T : class
118+
{
119+
return _host.Services.GetService(typeof(T)) as T;
120+
}
123121

124-
// Configuration
125-
services.Configure<AppConfig>(context.Configuration.GetSection(nameof(AppConfig)));
122+
/// <summary>
123+
/// Occurs when the application is loading.
124+
/// </summary>
125+
private async void OnStartup(object sender, StartupEventArgs e)
126+
{
127+
await _host.StartAsync();
126128
}
127129

128130
/// <summary>
@@ -133,7 +135,6 @@ private async void OnExit(object sender, ExitEventArgs e)
133135
await _host.StopAsync();
134136

135137
_host.Dispose();
136-
_host = null;
137138
}
138139

139140
/// <summary>

src/Wpf.Ui.Demo/Views/Container.xaml.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,27 @@ public partial class Container : INavigationWindow
2727

2828
private readonly ITaskBarService _taskBarService;
2929

30+
public ContainerViewModel ViewModel
31+
{
32+
get;
33+
}
34+
3035
// NOTICE: In the case of this window, we navigate to the Dashboard after loading with Container.InitializeUi()
3136

3237
public Container(ContainerViewModel viewModel, INavigationService navigationService, IPageService pageService, IThemeService themeService, ITaskBarService taskBarService, ISnackbarService snackbarService, IDialogService dialogService)
3338
{
39+
// Assign the view model
40+
ViewModel = viewModel;
41+
DataContext = this;
42+
3443
// Attach the theme service
3544
_themeService = themeService;
3645

3746
// Attach the taskbar service
3847
_taskBarService = taskBarService;
3948

40-
// Context provided by the service provider.
41-
DataContext = viewModel;
49+
//// Context provided by the service provider.
50+
//DataContext = viewModel;
4251

4352
// Initial preparation of the window.
4453
InitializeComponent();

src/Wpf.Ui.Demo/Views/Pages/Buttons.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
99
xmlns:viewModels="clr-namespace:Wpf.Ui.Demo.ViewModels"
1010
Title="Buttons"
11-
d:DataContext="{d:DesignInstance viewModels:ButtonsViewModel,
11+
d:DataContext="{d:DesignInstance local:Buttons,
1212
IsDesignTimeCreatable=False}"
1313
d:DesignHeight="850"
1414
d:DesignWidth="800"
@@ -26,7 +26,7 @@
2626

2727
<ui:CardAction
2828
Margin="0,24,0,0"
29-
Command="{Binding ViewCommand}"
29+
Command="{Binding ViewModel.ViewCommand}"
3030
CommandParameter="show_more"
3131
Icon="TextParagraph24">
3232
<StackPanel>

src/Wpf.Ui.Demo/Views/Pages/Buttons.xaml.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// All Rights Reserved.
55

66
using Wpf.Ui.Demo.ViewModels;
7+
using Wpf.Ui.Mvvm.Contracts;
78

89
namespace Wpf.Ui.Demo.Views.Pages;
910

@@ -12,9 +13,20 @@ namespace Wpf.Ui.Demo.Views.Pages;
1213
/// </summary>
1314
public partial class Buttons
1415
{
16+
public ButtonsViewModel ViewModel
17+
{
18+
get;
19+
}
20+
1521
public Buttons(ButtonsViewModel viewModel)
1622
{
17-
DataContext = viewModel;
23+
//ViewModel = App.GetService<ButtonsViewModel>();
24+
ViewModel = viewModel;
25+
DataContext = this;
26+
27+
var testGetThemeService = App.GetService<IThemeService>();
28+
var currentTheme = testGetThemeService.GetSystemTheme();
29+
1830
InitializeComponent();
1931
}
2032
}

src/Wpf.Ui.FontMapper/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
enumMapStringBuilder.AppendLine("");
6969

7070
enumMapStringBuilder.AppendLine("/// <summary>");
71-
enumMapStringBuilder.AppendLine($"/// {singleFont.Description.Replace("\n", "\n///")}");
71+
enumMapStringBuilder.AppendLine($"/// {singleFont.Description.Replace("\n", "\n/// ")}");
7272
enumMapStringBuilder.AppendLine("/// </summary>");
7373

7474
enumMapStringBuilder.AppendLine("#pragma warning disable CS1591");

src/Wpf.Ui/Common/SymbolFilled.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Wpf.Ui.Common;
77

88
/// <summary>
99
/// Represents a list of filled Fluent System Icons <c>v.1.1.175</c>.
10-
///<para>May be converted to <see langword="char"/> using <c>GetGlyph()</c> or to <see langword="string"/> using <c>GetString()</c></para>
10+
/// <para>May be converted to <see langword="char"/> using <c>GetGlyph()</c> or to <see langword="string"/> using <c>GetString()</c></para>
1111
/// </summary>
1212
#pragma warning disable CS1591
1313
public enum SymbolFilled

src/Wpf.Ui/Common/SymbolRegular.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Wpf.Ui.Common;
77

88
/// <summary>
99
/// Represents a list of regular Fluent System Icons <c>v.1.1.175</c>.
10-
///<para>May be converted to <see langword="char"/> using <c>GetGlyph()</c> or to <see langword="string"/> using <c>GetString()</c></para>
10+
/// <para>May be converted to <see langword="char"/> using <c>GetGlyph()</c> or to <see langword="string"/> using <c>GetString()</c></para>
1111
/// </summary>
1212
#pragma warning disable CS1591
1313
public enum SymbolRegular

0 commit comments

Comments
 (0)