Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions samples/WpfDemoLib/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
namespace WpfDemoLib.ViewModels;

public sealed class MainViewModel : ObservableObject {
public const string NotificationWarningIconResourceName =
"pack://application:,,,/WpfDemoLib;component/assets/images/icons8-notification-warning-32.png";

private string? _fileDialogResults;
private string? _secondWindowResult;

Expand Down Expand Up @@ -64,6 +61,7 @@ public MainViewModel(
public IRelayCommand ShowDialogOpenFileCommand { get; set; }
public IRelayCommand ShowDialogSaveFileCommand { get; set; }
public IRelayCommand ShowDialogOpenFolderCommand { get; set; }
public IRelayCommand ShowNotificationCommand { get; set; }

public string? FileDialogResults {
get => _fileDialogResults;
Expand Down
61 changes: 61 additions & 0 deletions samples/WpfDemoLib/ViewModels/Pages/NotificationViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Windows.Input;
using System.Windows.Media.Imaging;

using dosymep.SimpleServices;

using WpfDemoLib.ComponentModel;
using WpfDemoLib.Factories;

namespace WpfDemoLib.ViewModels.Pages;

public sealed class NotificationViewModel : ObservableObject {
public const string NotificationWarningIconResourceName =
"pack://application:,,,/WpfDemoLib;component/assets/images/icons8-notification-warning-32.png";

public INotificationService NotificationService { get; }

public NotificationViewModel(ICommandFactory commandFactory, INotificationService notificationService) {
NotificationService = notificationService;

ShowNotificationCommand = commandFactory.CreateAsync(ShowNotificationAsync);
ShowFatalNotificationCommand = commandFactory.CreateAsync(ShowFatalNotificationAsync);
ShowWarningNotificationCommand = commandFactory.CreateAsync(ShowWarningNotificationAsync);
}

public ICommand ShowNotificationCommand { get; }
public ICommand ShowFatalNotificationCommand { get; }
public ICommand ShowWarningNotificationCommand { get; }

private int _count = 0;

private async Task ShowNotificationAsync() {
INotification notification = NotificationService.CreateNotification(
title: "Title " + _count++,
body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
footer: "IronPython",
author: "dosymep",
imageSource: new BitmapImage(new Uri(NotificationWarningIconResourceName, UriKind.Absolute)));

await notification.ShowAsync();
}

private async Task ShowFatalNotificationAsync() {
INotification notification = NotificationService.CreateFatalNotification(
title: "IronPython " + _count++,
body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
author: "dosymep",
imageSource: new BitmapImage(new Uri(NotificationWarningIconResourceName, UriKind.Absolute)));

await notification.ShowAsync();
}

private async Task ShowWarningNotificationAsync() {
INotification notification = NotificationService.CreateWarningNotification(
title: "IronPython " + _count++,
body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
author: "dosymep",
imageSource: new BitmapImage(new Uri(NotificationWarningIconResourceName, UriKind.Absolute)));

await notification.ShowAsync();
}
}
50 changes: 29 additions & 21 deletions samples/WpfUIDemoApp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using dosymep.SimpleServices;
using dosymep.WpfCore.Ninject;
using dosymep.WpfCore.SimpleServices;
using dosymep.WpfUI.Core.Ninject;

using Ninject;
Expand All @@ -18,9 +19,11 @@
using WpfDemoLib.Input.Interfaces;
using WpfDemoLib.Services;
using WpfDemoLib.ViewModels;
using WpfDemoLib.ViewModels.Pages;

using WpfUIDemoApp.Factories;
using WpfUIDemoApp.Views;
using WpfUIDemoApp.Views.Pages;

namespace WpfUIDemoApp;

Expand All @@ -30,61 +33,66 @@ namespace WpfUIDemoApp;
public partial class App {
public const string LocalizationResourceName =
"/WpfUIDemoApp;component/assets/localizations/language.xaml";

public const string NotificationIconResourceName =
"pack://application:,,,/WpfUIDemoApp;component/assets/images/icons8-notification-32.png";

public const string NotificationWarningIconResourceName =
"pack://application:,,,/WpfUIDemoApp;component/assets/images/icons8-notification-warning-32.png";

private IKernel? _kernel;

protected override void OnStartup(StartupEventArgs e) {
base.OnStartup(e);

_kernel = new StandardKernel();

_kernel.Bind<ICommandFactory>().To<RelayCommandFactory>();

_kernel.UseWpfDispatcher();

_kernel.UseWpfWindowsLanguage();
_kernel.UseWpfLocalization(LocalizationResourceName, CultureInfo.GetCultureInfo("ru-RU"));

_kernel.UseWpfWindowsTheme();
_kernel.UseWpfUIThemeUpdater();

ILocalizationService localizationService = _kernel.Get<ILocalizationService>();

_kernel.UseWpfUIMessageBox<MainViewModel>();

_kernel.UseWpfUINotifications<NotificationViewModel>();

_kernel.UseWpfUIProgressDialog<MainViewModel>(
displayTitleFormat: localizationService.GetLocalizedString("ProgressDialog.Content"));

_kernel.UseWpfOpenFileDialog<MainViewModel>(
title: localizationService.GetLocalizedString("OpenFileDialog.Title"));

_kernel.UseWpfSaveFileDialog<MainViewModel>(
title: localizationService.GetLocalizedString("SaveFileDialog.Title"));

_kernel.UseWpfOpenFolderDialog<MainViewModel>(
title: localizationService.GetLocalizedString("OpenFolderDialog.Title"));

_kernel.Bind<ISecondViewService>().To<SecondViewService>();
_kernel.Bind<ISecondViewFactory>()
.ToMethod(c => new SecondViewFactory<SecondWindow>(() => c.Kernel.Get<SecondWindow>()));

_kernel.Bind<INavigationViewPageProvider>()
.To<NavigationViewPageProvider>();

_kernel.Bind<SecondWindow>().ToSelf();
_kernel.Bind<SecondViewModel>().ToSelf();



_kernel.Bind<NotificationPage>().ToSelf().InSingletonScope();
_kernel.Bind<NotificationViewModel>().ToSelf().InSingletonScope();

_kernel.BindMainWindow<MainViewModel, MainWindow>();

_kernel.Get<MainWindow>().Show();
}

protected override void OnExit(ExitEventArgs e) {
base.OnExit(e);
_kernel?.Dispose();
Expand Down
9 changes: 7 additions & 2 deletions samples/WpfUIDemoApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
xmlns:behaviors="clr-namespace:dosymep.WpfCore.Behaviors;assembly=dosymep.WpfCore"
xmlns:viewModels="clr-namespace:WpfDemoLib.ViewModels;assembly=WpfDemoLib"
xmlns:pages="clr-namespace:WpfUIDemoApp.Views.Pages"

Height="600"
Width="1000"

Expand All @@ -37,7 +37,7 @@
<behaviors:WpfAttachServiceBehavior AttachableService="{Binding OpenFileDialogService}" />
<behaviors:WpfAttachServiceBehavior AttachableService="{Binding SaveFileDialogService}" />
<behaviors:WpfAttachServiceBehavior AttachableService="{Binding OpenFolderDialogService}" />
</b:Interaction.Behaviors>
</b:Interaction.Behaviors>

<b:Interaction.Triggers>
<b:EventTrigger
Expand Down Expand Up @@ -142,6 +142,11 @@
Content="{me:LocalizationSource MainWindow.GridPageTitle}"
Icon="{ui:SymbolIcon Settings16}"
TargetPageType="{x:Type pages:GridViewPage}" />

<ui:NavigationViewItem
Content="{me:LocalizationSource MainWindow.NotificationPage.Title}"
Icon="{ui:SymbolIcon Alert24}"
TargetPageType="{x:Type pages:NotificationPage}" />
</ui:NavigationView.MenuItems>

<ui:NavigationView.FooterMenuItems>
Expand Down
43 changes: 43 additions & 0 deletions samples/WpfUIDemoApp/Views/Pages/NotificationPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<local:WpfUIPlatformPage
x:Class="WpfUIDemoApp.Views.Pages.NotificationPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfUIDemoApp.Views.Pages"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:behaviors="clr-namespace:dosymep.WpfCore.Behaviors;assembly=dosymep.WpfCore"
xmlns:me="clr-namespace:dosymep.WpfCore.MarkupExtensions;assembly=dosymep.WpfCore"
xmlns:viewModels="clr-namespace:WpfDemoLib.ViewModels;assembly=WpfDemoLib"
xmlns:pages="clr-namespace:WpfDemoLib.ViewModels.Pages;assembly=WpfDemoLib"

mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"

ui:NavigationView.HeaderContent="{me:LocalizationSource NotificationPage.Title}"

Foreground="{DynamicResource TextFillColorPrimaryBrush}"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"

d:DataContext="{d:DesignInstance pages:NotificationViewModel, IsDesignTimeCreatable=False}">

<b:Interaction.Behaviors>
<behaviors:WpfAttachServiceBehavior AttachableService="{Binding NotificationService}" />
</b:Interaction.Behaviors>

<StackPanel>
<ui:Button
Content="{me:LocalizationSource NotificationPage.ShowNotification}"
Command="{Binding ShowNotificationCommand}" />

<ui:Button
Content="{me:LocalizationSource NotificationPage.ShowFatalNotification}"
Command="{Binding ShowFatalNotificationCommand}" />

<ui:Button
Content="{me:LocalizationSource NotificationPage.ShowWarningNotification}"
Command="{Binding ShowWarningNotificationCommand}" />
</StackPanel>
</local:WpfUIPlatformPage>
19 changes: 19 additions & 0 deletions samples/WpfUIDemoApp/Views/Pages/NotificationPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Windows.Controls;

using dosymep.SimpleServices;

using WpfDemoLib.ViewModels;
using WpfDemoLib.ViewModels.Pages;

namespace WpfUIDemoApp.Views.Pages;

public partial class NotificationPage {
public NotificationPage(
IHasTheme hasTheme,
IHasLocalization hasLocalization,
NotificationViewModel notificationViewModel)
: base(hasTheme, hasLocalization) {
InitializeComponent();
DataContext = notificationViewModel;
}
}
14 changes: 7 additions & 7 deletions samples/WpfUIDemoApp/Views/Pages/WpfUIPlatformPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace WpfUIDemoApp.Views.Pages {
public class WpfUIPlatformPage : Page, IHasTheme, IHasLocalization {
public event Action<UIThemes>? ThemeChanged;
public event Action<CultureInfo>? LanguageChanged;
private readonly IHasTheme? _hasTheme;
private readonly IHasLocalization? _hasLocalization;
public event Action<UIThemes> ThemeChanged = null!;
public event Action<CultureInfo> LanguageChanged = null!;

private readonly IHasTheme _hasTheme = null!;
private readonly IHasLocalization _hasLocalization = null!;

public WpfUIPlatformPage() { }

Expand All @@ -24,7 +24,7 @@ public WpfUIPlatformPage(

_hasTheme.ThemeChanged += _ => ThemeChanged?.Invoke(_);
_hasLocalization.LanguageChanged += _ => LanguageChanged?.Invoke(_);

Interaction.GetBehaviors(this).Add(new WpfThemeBehavior());
Interaction.GetBehaviors(this).Add(new WpfLocalizationBehavior());
}
Expand All @@ -35,4 +35,4 @@ public WpfUIPlatformPage(
public UIThemes HostTheme => _hasTheme.HostTheme;
public CultureInfo HostLanguage => _hasLocalization.HostLanguage;
}
}
}
5 changes: 5 additions & 0 deletions samples/WpfUIDemoApp/assets/localizations/language.en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<system:String x:Key="MainWindow.ButtonDialogSaveFileCommand">Save file</system:String>
<system:String x:Key="MainWindow.ButtonDialogOpenFolderCommand">Choose folder</system:String>

<system:String x:Key="NotificationPage.Title">Notifications</system:String>
<system:String x:Key="NotificationPage.ShowNotification">Show notification</system:String>
<system:String x:Key="NotificationPage.ShowFatalNotification">Show fatal notification</system:String>
<system:String x:Key="NotificationPage.ShowWarningNotification">Show warning notification</system:String>

<system:String x:Key="UIThemes.Dark">Dark</system:String>
<system:String x:Key="UIThemes.Light">Light</system:String>
</ResourceDictionary>
5 changes: 5 additions & 0 deletions samples/WpfUIDemoApp/assets/localizations/language.ru-RU.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
<system:String x:Key="MainWindow.ButtonDialogSaveFileCommand">Сохранить файл</system:String>
<system:String x:Key="MainWindow.ButtonDialogOpenFolderCommand">Выбрать папку</system:String>

<system:String x:Key="NotificationPage.Title">Уведомления</system:String>
<system:String x:Key="NotificationPage.ShowNotification">Показать уведомление</system:String>
<system:String x:Key="NotificationPage.ShowFatalNotification">Показать ошибку</system:String>
<system:String x:Key="NotificationPage.ShowWarningNotification">Показать предупреждение</system:String>

<system:String x:Key="UIThemes.Dark">Темная</system:String>
<system:String x:Key="UIThemes.Light">Светлая</system:String>
</ResourceDictionary>
41 changes: 41 additions & 0 deletions src/dosymep.WpfCore/Animations/NotificationAnimations.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<ExponentialEase x:Key="ExponentialEase" Exponent="5" />

<Storyboard x:Key="Showing">
<DoubleAnimation
From="0" To="1"
Duration="0:0:0.3"
Storyboard.TargetProperty="Opacity" />

<DoubleAnimation
From="385" To="0"
Duration="0:0:0.3"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)"
EasingFunction="{StaticResource ExponentialEase}" />
</Storyboard>

<Storyboard x:Key="Closing">
<DoubleAnimation
To="385"
Duration="0:0:0.3"
EasingFunction="{StaticResource ExponentialEase}"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" />
</Storyboard>

<Storyboard x:Key="AutoClosing">
<DoubleAnimation
From="1" To="0"
Duration="0:0:0.3"
Storyboard.TargetProperty="Opacity" />
</Storyboard>

<Storyboard x:Key="Positioning">
<DoubleAnimation
To="90"
Duration="0:0:0.3"
EasingFunction="{StaticResource ExponentialEase}"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" />
</Storyboard>
</ResourceDictionary>
Loading
Loading