Skip to content

Commit 9f73807

Browse files
authored
Merge pull request #1165 from lepoco/development
Release 3.0.5
2 parents 303f0ae + 63f0f0c commit 9f73807

File tree

106 files changed

+1070
-408
lines changed

Some content is hidden

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

106 files changed

+1070
-408
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>3.0.4</Version>
3+
<Version>3.0.5</Version>
44
<LangVersion>12.0</LangVersion>
55
<Deterministic>true</Deterministic>
66
</PropertyGroup>

docs/documentation/navigation-view.md

+154
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,157 @@ RootNavigation.Navigate(2);
6969
```
7070

7171
## Pane display mode
72+
73+
## Set initial page
74+
75+
NavigationPage.xaml
76+
77+
```xml
78+
<ui:NavigationView x:Name="RootNavigation"></ui:NavigationView>
79+
```
80+
81+
NavigationPage.xaml.cs
82+
83+
```csharp
84+
public partial class NavigationPage : Page
85+
{
86+
public NavigationPage(NavigationPageModel model)
87+
{
88+
InitializeComponent();
89+
90+
DataContext = model;
91+
Loaded += (_, _) => RootNavigation.Navigate(type(MyDashboardClass));
92+
}
93+
}
94+
```
95+
96+
## Using Navigation in the MVVM
97+
98+
Firstly, you need to implement the `IPageService` interface
99+
100+
```csharp
101+
// from src/Wpf.Ui.Demo.Mvvm/Services/PageService.cs
102+
public class PageService : IPageService
103+
{
104+
/// <summary>
105+
/// Service which provides the instances of pages.
106+
/// </summary>
107+
private readonly IServiceProvider _serviceProvider;
108+
109+
/// <summary>
110+
/// Initializes a new instance of the <see cref="PageService"/> class and attaches the <see cref="IServiceProvider"/>.
111+
/// </summary>
112+
public PageService(IServiceProvider serviceProvider)
113+
{
114+
_serviceProvider = serviceProvider;
115+
}
116+
117+
/// <inheritdoc />
118+
public T? GetPage<T>()
119+
where T : class
120+
{
121+
if (!typeof(FrameworkElement).IsAssignableFrom(typeof(T)))
122+
{
123+
throw new InvalidOperationException("The page should be a WPF control.");
124+
}
125+
126+
return (T?)_serviceProvider.GetService(typeof(T));
127+
}
128+
129+
/// <inheritdoc />
130+
public FrameworkElement? GetPage(Type pageType)
131+
{
132+
if (!typeof(FrameworkElement).IsAssignableFrom(pageType))
133+
{
134+
throw new InvalidOperationException("The page should be a WPF control.");
135+
}
136+
137+
return _serviceProvider.GetService(pageType) as FrameworkElement;
138+
}
139+
}
140+
```
141+
142+
Then, inject it into the IoC container.
143+
144+
```csharp
145+
var services = new ServiceCollection();
146+
147+
services.AddSingleton<MainWindow>();
148+
services.AddSingleton<MainWindowViewModel>();
149+
services.AddSingleton<IPageService, PageService>();
150+
151+
// inject View and ViewModel
152+
services.AddSingleton<MainWindow>();
153+
services.AddSingleton<MainWindowViewModel>();
154+
services.AddSingleton<HomePage>();
155+
services.AddSingleton<HomePageModel>();
156+
services.AddSingleton<CounterPage>();
157+
services.AddSingleton<CounterPageModel>();
158+
```
159+
160+
Lastly, adjust the code for the navigation window.
161+
162+
```xml
163+
<Window
164+
x:Class="NavigationDemo.MainWindow"
165+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
166+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
167+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
168+
xmlns:local="clr-namespace:NavigationDemo"
169+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
170+
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
171+
Title="Navigation Window"
172+
Width="800"
173+
Height="450"
174+
d:DataContext="{d:DesignInstance local:MainWindowViewModel}"
175+
mc:Ignorable="d">
176+
177+
<ui:NavigationView x:Name="RootNavigationView" MenuItemsSource="{Binding NavigationItems}"/>
178+
</Window>
179+
```
180+
181+
```csharp
182+
using System.Collections.ObjectModel;
183+
using System.Windows;
184+
using CommunityToolkit.Mvvm.ComponentModel;
185+
using Wpf.Ui;
186+
using Wpf.Ui.Controls;
187+
188+
public partial class MainWindow : Window
189+
{
190+
public MainWindow(IPageService pageService, MainWindowViewModel model)
191+
{
192+
DataContext = model;
193+
InitializeComponent();
194+
195+
// Set the page service for the navigation control.
196+
RootNavigationView.SetPageService(pageService);
197+
}
198+
}
199+
200+
public partial class MainWindowViewModel : ObservableObject
201+
{
202+
[ObservableProperty]
203+
private ObservableCollection<object> _navigationItems = [];
204+
205+
public MainWindowViewModel()
206+
{
207+
NavigationItems =
208+
[
209+
new NavigationViewItem()
210+
{
211+
Content = "Home",
212+
Icon = new SymbolIcon { Symbol = SymbolRegular.Home24 },
213+
TargetPageType = typeof(HomePage)
214+
},
215+
new NavigationViewItem()
216+
{
217+
Content = "Counter",
218+
TargetPageType = typeof(CounterPage)
219+
},
220+
];
221+
}
222+
}
223+
```
224+
225+
Alternatively, you can use the **WPF UI** Visual Studio Extension that includes a project template for MVVM pattern.

docs/documentation/nuget.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ NuGet is a free, open-source package management system for the Microsoft .NET pl
2828

2929
# Done!
3030

31-
Package installed, to learn more, go to the [**Getting started**](/tutorial/getting-started.html) page.
31+
Package installed, to learn more, go to the [**Getting started**](/documentation/getting-started.html) page.

docs/documentation/themes.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Or, you can add **WPF UI** resources manually.
2424
<Application.Resources>
2525
<ResourceDictionary>
2626
<ResourceDictionary.MergedDictionaries>
27-
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui;component/Styles/Theme/Dark.xaml" />
28-
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui;component/Styles/Wpf.Ui.xaml" />
27+
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui;component/Resources/Theme/Dark.xaml" />
28+
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui;component/Resources/Wpf.Ui.xaml" />
2929
</ResourceDictionary.MergedDictionaries>
3030
</ResourceDictionary>
3131
</Application.Resources>
@@ -37,16 +37,16 @@ Or, you can add **WPF UI** resources manually.
3737
If you want to change the theme while the application is running, you can call the static `Apply` method of the `Theme` class.
3838

3939
```csharp
40-
Wpf.Ui.Appearance.Theme.Apply(
41-
Wpf.Ui.Appearance.ThemeType.Light, // Theme type
42-
Wpf.Ui.Appearance.BackgroundType.Mica, // Background type
43-
true // Whether to change accents automatically
40+
Wpf.Ui.Appearance.ApplicationThemeManager.Apply(
41+
Wpf.Ui.Appearance.ApplicationTheme.Light, // Theme type
42+
Wpf.Ui.Controls.WindowBackdropType.Mica, // Background type
43+
true // Whether to change accents automatically
4444
);
4545
```
4646

4747
### Automatic change
4848

49-
The theme can be changed automatically when the operating system changes its background or accent using the [Watcher](https://github.com/lepoco/wpfui/blob/main/src/Wpf.Ui/Appearance/Watcher.cs) class.
49+
The theme can be changed automatically when the operating system changes its background or accent using the [SystemThemeWatcher](https://github.com/lepoco/wpfui/blob/main/src/Wpf.Ui/Appearance/SystemThemeWatcher.cs) class.
5050

5151
```csharp
5252
namespace MyApp;
@@ -59,10 +59,10 @@ public partial class MainWindow : Window
5959

6060
Loaded += (sender, args) =>
6161
{
62-
Wpf.Ui.Appearance.Watcher.Watch(
63-
this, // Window class
64-
Wpf.Ui.Appearance.BackgroundType.Mica, // Background type
65-
true // Whether to change accents automatically
62+
Wpf.Ui.Appearance.SystemThemeWatcher.Watch(
63+
this, // Window class
64+
Wpf.Ui.Controls.WindowBackdropType.Mica, // Background type
65+
true // Whether to change accents automatically
6666
);
6767
};
6868
}

src/Wpf.Ui.Demo.Simple/AssemblyInfo.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// This Source Code Form is subject to the terms of the MIT License.
2+
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
3+
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
4+
// All Rights Reserved.
5+
16
using System.Windows;
27

38
[assembly: ThemeInfo(

src/Wpf.Ui.Extension.Template.Blank/App.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public partial class App
2020
// https://docs.microsoft.com/dotnet/core/extensions/logging
2121
private static readonly IHost _host = Host
2222
.CreateDefaultBuilder()
23-
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); })
23+
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)); })
2424
.ConfigureServices((context, services) =>
2525
{
2626
throw new NotImplementedException("No service or window was registered.");

src/Wpf.Ui.Extension.Template.Compact/App.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class App
2525
// https://docs.microsoft.com/dotnet/core/extensions/logging
2626
private static readonly IHost _host = Host
2727
.CreateDefaultBuilder()
28-
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); })
28+
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)); })
2929
.ConfigureServices((context, services) =>
3030
{
3131
services.AddHostedService<ApplicationHostService>();

src/Wpf.Ui.Extension.Template.Fluent/App.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class App
2525
// https://docs.microsoft.com/dotnet/core/extensions/logging
2626
private static readonly IHost _host = Host
2727
.CreateDefaultBuilder()
28-
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); })
28+
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)); })
2929
.ConfigureServices((context, services) =>
3030
{
3131
services.AddHostedService<ApplicationHostService>();

src/Wpf.Ui.FontMapper/FontSource.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// This Source Code Form is subject to the terms of the MIT License.
2+
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
3+
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
4+
// All Rights Reserved.
5+
16
namespace Wpf.Ui.FontMapper;
27

38
class FontSource

src/Wpf.Ui.FontMapper/GitTag.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
namespace Wpf.Ui.FontMapper;
1+
// This Source Code Form is subject to the terms of the MIT License.
2+
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
3+
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
4+
// All Rights Reserved.
5+
6+
namespace Wpf.Ui.FontMapper;
27

38
record GitTag(string Ref, string Node_Id, string Url);

src/Wpf.Ui.Gallery/Views/Pages/Layout/ExpanderPage.xaml.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
using Wpf.Ui.Controls;
1+
// This Source Code Form is subject to the terms of the MIT License.
2+
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
3+
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
4+
// All Rights Reserved.
5+
6+
using Wpf.Ui.Controls;
27
using Wpf.Ui.Gallery.ControlsLookup;
38
using Wpf.Ui.Gallery.ViewModels.Pages.Layout;
49

src/Wpf.Ui.SyntaxHighlight/Highlighter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
33
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
44
// All Rights Reserved.
5-
//
5+
66
// TODO: This class is work in progress.
77

88
using System;

src/Wpf.Ui.Tray/Controls/NotifyIcon.cs

+2
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ private static void OnTooltipTextChanged(DependencyObject d, DependencyPropertyC
388388
}
389389

390390
notifyIcon.TooltipText = e.NewValue as string ?? string.Empty;
391+
notifyIcon.internalNotifyIconManager.TooltipText = notifyIcon.TooltipText;
392+
_ = notifyIcon.internalNotifyIconManager.ModifyToolTip();
391393
}
392394

393395
private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

src/Wpf.Ui.Tray/Hicon.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
33
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
44
// All Rights Reserved.
5-
//
5+
66
// TODO: This class is the only reason for using System.Drawing.Common.
77
// It is worth looking for a way to get hIcon without using it.
88

src/Wpf.Ui.Tray/INotifyIcon.cs

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ internal interface INotifyIcon
8282
/// </summary>
8383
bool ModifyIcon();
8484

85+
/// <summary>
86+
/// Tries to modify the tooltip of the <see cref="INotifyIcon"/> in the shell.
87+
/// </summary>
88+
bool ModifyToolTip();
89+
8590
/// <summary>
8691
/// Tries to remove the <see cref="INotifyIcon"/> from the shell.
8792
/// </summary>

src/Wpf.Ui.Tray/Internal/InternalNotifyIconManager.cs

+6
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public virtual bool ModifyIcon()
104104
return TrayManager.ModifyIcon(this);
105105
}
106106

107+
/// <inheritdoc />
108+
public virtual bool ModifyToolTip()
109+
{
110+
return TrayManager.ModifyToolTip(this);
111+
}
112+
107113
/// <inheritdoc />
108114
public virtual bool Unregister()
109115
{

src/Wpf.Ui.Tray/TrayManager.cs

+13
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ public static bool ModifyIcon(INotifyIcon notifyIcon)
124124
return Interop.Shell32.Shell_NotifyIcon(Interop.Shell32.NIM.MODIFY, notifyIcon.ShellIconData);
125125
}
126126

127+
public static bool ModifyToolTip(INotifyIcon notifyIcon)
128+
{
129+
if (!notifyIcon.IsRegistered)
130+
{
131+
return true;
132+
}
133+
134+
notifyIcon.ShellIconData.szTip = notifyIcon.TooltipText;
135+
notifyIcon.ShellIconData.uFlags |= Interop.Shell32.NIF.TIP;
136+
137+
return Interop.Shell32.Shell_NotifyIcon(Interop.Shell32.NIM.MODIFY, notifyIcon.ShellIconData);
138+
}
139+
127140
/// <summary>
128141
/// Tries to remove the <see cref="INotifyIcon"/> from the shell.
129142
/// </summary>

src/Wpf.Ui/Appearance/ApplicationThemeManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static void Apply(
9797
SystemTheme.HC1 => "HC1",
9898
SystemTheme.HC2 => "HC2",
9999
SystemTheme.HCBlack => "HCBlack",
100-
SystemTheme.HCWhite => "HCBlack",
100+
SystemTheme.HCWhite => "HCWhite",
101101
_ => "HCWhite",
102102
};
103103
break;

0 commit comments

Comments
 (0)