Skip to content

Commit

Permalink
Merge pull request #1165 from lepoco/development
Browse files Browse the repository at this point in the history
Release 3.0.5
  • Loading branch information
pomianowski committed Jul 24, 2024
2 parents 303f0ae + 63f0f0c commit 9f73807
Show file tree
Hide file tree
Showing 106 changed files with 1,070 additions and 408 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.0.4</Version>
<Version>3.0.5</Version>
<LangVersion>12.0</LangVersion>
<Deterministic>true</Deterministic>
</PropertyGroup>
Expand Down
154 changes: 154 additions & 0 deletions docs/documentation/navigation-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,157 @@ RootNavigation.Navigate(2);
```

## Pane display mode

## Set initial page

NavigationPage.xaml

```xml
<ui:NavigationView x:Name="RootNavigation"></ui:NavigationView>
```

NavigationPage.xaml.cs

```csharp
public partial class NavigationPage : Page
{
public NavigationPage(NavigationPageModel model)
{
InitializeComponent();

DataContext = model;
Loaded += (_, _) => RootNavigation.Navigate(type(MyDashboardClass));
}
}
```

## Using Navigation in the MVVM

Firstly, you need to implement the `IPageService` interface

```csharp
// from src/Wpf.Ui.Demo.Mvvm/Services/PageService.cs
public class PageService : IPageService
{
/// <summary>
/// Service which provides the instances of pages.
/// </summary>
private readonly IServiceProvider _serviceProvider;

/// <summary>
/// Initializes a new instance of the <see cref="PageService"/> class and attaches the <see cref="IServiceProvider"/>.
/// </summary>
public PageService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}

/// <inheritdoc />
public T? GetPage<T>()
where T : class
{
if (!typeof(FrameworkElement).IsAssignableFrom(typeof(T)))
{
throw new InvalidOperationException("The page should be a WPF control.");
}

return (T?)_serviceProvider.GetService(typeof(T));
}

/// <inheritdoc />
public FrameworkElement? GetPage(Type pageType)
{
if (!typeof(FrameworkElement).IsAssignableFrom(pageType))
{
throw new InvalidOperationException("The page should be a WPF control.");
}

return _serviceProvider.GetService(pageType) as FrameworkElement;
}
}
```

Then, inject it into the IoC container.

```csharp
var services = new ServiceCollection();

services.AddSingleton<MainWindow>();
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<IPageService, PageService>();

// inject View and ViewModel
services.AddSingleton<MainWindow>();
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<HomePage>();
services.AddSingleton<HomePageModel>();
services.AddSingleton<CounterPage>();
services.AddSingleton<CounterPageModel>();
```

Lastly, adjust the code for the navigation window.

```xml
<Window
x:Class="NavigationDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:NavigationDemo"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="Navigation Window"
Width="800"
Height="450"
d:DataContext="{d:DesignInstance local:MainWindowViewModel}"
mc:Ignorable="d">

<ui:NavigationView x:Name="RootNavigationView" MenuItemsSource="{Binding NavigationItems}"/>
</Window>
```

```csharp
using System.Collections.ObjectModel;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using Wpf.Ui;
using Wpf.Ui.Controls;

public partial class MainWindow : Window
{
public MainWindow(IPageService pageService, MainWindowViewModel model)
{
DataContext = model;
InitializeComponent();

// Set the page service for the navigation control.
RootNavigationView.SetPageService(pageService);
}
}

public partial class MainWindowViewModel : ObservableObject
{
[ObservableProperty]
private ObservableCollection<object> _navigationItems = [];

public MainWindowViewModel()
{
NavigationItems =
[
new NavigationViewItem()
{
Content = "Home",
Icon = new SymbolIcon { Symbol = SymbolRegular.Home24 },
TargetPageType = typeof(HomePage)
},
new NavigationViewItem()
{
Content = "Counter",
TargetPageType = typeof(CounterPage)
},
];
}
}
```

Alternatively, you can use the **WPF UI** Visual Studio Extension that includes a project template for MVVM pattern.
2 changes: 1 addition & 1 deletion docs/documentation/nuget.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ NuGet is a free, open-source package management system for the Microsoft .NET pl

# Done!

Package installed, to learn more, go to the [**Getting started**](/tutorial/getting-started.html) page.
Package installed, to learn more, go to the [**Getting started**](/documentation/getting-started.html) page.
22 changes: 11 additions & 11 deletions docs/documentation/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Or, you can add **WPF UI** resources manually.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui;component/Styles/Theme/Dark.xaml" />
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui;component/Styles/Wpf.Ui.xaml" />
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui;component/Resources/Theme/Dark.xaml" />
<ResourceDictionary Source="pack://application:,,,/Wpf.Ui;component/Resources/Wpf.Ui.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand All @@ -37,16 +37,16 @@ Or, you can add **WPF UI** resources manually.
If you want to change the theme while the application is running, you can call the static `Apply` method of the `Theme` class.

```csharp
Wpf.Ui.Appearance.Theme.Apply(
Wpf.Ui.Appearance.ThemeType.Light, // Theme type
Wpf.Ui.Appearance.BackgroundType.Mica, // Background type
true // Whether to change accents automatically
Wpf.Ui.Appearance.ApplicationThemeManager.Apply(
Wpf.Ui.Appearance.ApplicationTheme.Light, // Theme type
Wpf.Ui.Controls.WindowBackdropType.Mica, // Background type
true // Whether to change accents automatically
);
```

### Automatic change

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.
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.

```csharp
namespace MyApp;
Expand All @@ -59,10 +59,10 @@ public partial class MainWindow : Window

Loaded += (sender, args) =>
{
Wpf.Ui.Appearance.Watcher.Watch(
this, // Window class
Wpf.Ui.Appearance.BackgroundType.Mica, // Background type
true // Whether to change accents automatically
Wpf.Ui.Appearance.SystemThemeWatcher.Watch(
this, // Window class
Wpf.Ui.Controls.WindowBackdropType.Mica, // Background type
true // Whether to change accents automatically
);
};
}
Expand Down
5 changes: 5 additions & 0 deletions src/Wpf.Ui.Demo.Simple/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Windows;

[assembly: ThemeInfo(
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui.Extension.Template.Blank/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial class App
// https://docs.microsoft.com/dotnet/core/extensions/logging
private static readonly IHost _host = Host
.CreateDefaultBuilder()
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); })
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)); })
.ConfigureServices((context, services) =>
{
throw new NotImplementedException("No service or window was registered.");
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui.Extension.Template.Compact/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class App
// https://docs.microsoft.com/dotnet/core/extensions/logging
private static readonly IHost _host = Host
.CreateDefaultBuilder()
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); })
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)); })
.ConfigureServices((context, services) =>
{
services.AddHostedService<ApplicationHostService>();
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui.Extension.Template.Fluent/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class App
// https://docs.microsoft.com/dotnet/core/extensions/logging
private static readonly IHost _host = Host
.CreateDefaultBuilder()
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); })
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)); })
.ConfigureServices((context, services) =>
{
services.AddHostedService<ApplicationHostService>();
Expand Down
5 changes: 5 additions & 0 deletions src/Wpf.Ui.FontMapper/FontSource.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

namespace Wpf.Ui.FontMapper;

class FontSource
Expand Down
7 changes: 6 additions & 1 deletion src/Wpf.Ui.FontMapper/GitTag.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
namespace Wpf.Ui.FontMapper;
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

namespace Wpf.Ui.FontMapper;

record GitTag(string Ref, string Node_Id, string Url);
7 changes: 6 additions & 1 deletion src/Wpf.Ui.Gallery/Views/Pages/Layout/ExpanderPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using Wpf.Ui.Controls;
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using Wpf.Ui.Controls;
using Wpf.Ui.Gallery.ControlsLookup;
using Wpf.Ui.Gallery.ViewModels.Pages.Layout;

Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui.SyntaxHighlight/Highlighter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
//

// TODO: This class is work in progress.

using System;
Expand Down
2 changes: 2 additions & 0 deletions src/Wpf.Ui.Tray/Controls/NotifyIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ private static void OnTooltipTextChanged(DependencyObject d, DependencyPropertyC
}

notifyIcon.TooltipText = e.NewValue as string ?? string.Empty;
notifyIcon.internalNotifyIconManager.TooltipText = notifyIcon.TooltipText;
_ = notifyIcon.internalNotifyIconManager.ModifyToolTip();
}

private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui.Tray/Hicon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
//

// TODO: This class is the only reason for using System.Drawing.Common.
// It is worth looking for a way to get hIcon without using it.

Check warning on line 7 in src/Wpf.Ui.Tray/Hicon.cs

View workflow job for this annotation

GitHub Actions / deploy

Check warning on line 7 in src/Wpf.Ui.Tray/Hicon.cs

View workflow job for this annotation

GitHub Actions / deploy

Check warning on line 7 in src/Wpf.Ui.Tray/Hicon.cs

View workflow job for this annotation

GitHub Actions / deploy

Check warning on line 7 in src/Wpf.Ui.Tray/Hicon.cs

View workflow job for this annotation

GitHub Actions / deploy

Check warning on line 7 in src/Wpf.Ui.Tray/Hicon.cs

View workflow job for this annotation

GitHub Actions / deploy


Expand Down
5 changes: 5 additions & 0 deletions src/Wpf.Ui.Tray/INotifyIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ internal interface INotifyIcon
/// </summary>
bool ModifyIcon();

/// <summary>
/// Tries to modify the tooltip of the <see cref="INotifyIcon"/> in the shell.
/// </summary>
bool ModifyToolTip();

/// <summary>
/// Tries to remove the <see cref="INotifyIcon"/> from the shell.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Wpf.Ui.Tray/Internal/InternalNotifyIconManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public virtual bool ModifyIcon()
return TrayManager.ModifyIcon(this);
}

/// <inheritdoc />
public virtual bool ModifyToolTip()
{
return TrayManager.ModifyToolTip(this);
}

/// <inheritdoc />
public virtual bool Unregister()
{
Expand Down
13 changes: 13 additions & 0 deletions src/Wpf.Ui.Tray/TrayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ public static bool ModifyIcon(INotifyIcon notifyIcon)
return Interop.Shell32.Shell_NotifyIcon(Interop.Shell32.NIM.MODIFY, notifyIcon.ShellIconData);
}

public static bool ModifyToolTip(INotifyIcon notifyIcon)
{
if (!notifyIcon.IsRegistered)
{
return true;
}

notifyIcon.ShellIconData.szTip = notifyIcon.TooltipText;
notifyIcon.ShellIconData.uFlags |= Interop.Shell32.NIF.TIP;

return Interop.Shell32.Shell_NotifyIcon(Interop.Shell32.NIM.MODIFY, notifyIcon.ShellIconData);
}

/// <summary>
/// Tries to remove the <see cref="INotifyIcon"/> from the shell.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui/Appearance/ApplicationThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static void Apply(
SystemTheme.HC1 => "HC1",
SystemTheme.HC2 => "HC2",
SystemTheme.HCBlack => "HCBlack",
SystemTheme.HCWhite => "HCBlack",
SystemTheme.HCWhite => "HCWhite",
_ => "HCWhite",
};
break;
Expand Down
Loading

0 comments on commit 9f73807

Please sign in to comment.