feat: add new Notification.
This commit is contained in:
34
demo/Ursa.Demo/Pages/NotificationDemo.axaml
Normal file
34
demo/Ursa.Demo/Pages/NotificationDemo.axaml
Normal file
@@ -0,0 +1,34 @@
|
||||
<UserControl x:Class="Ursa.Demo.Pages.NotificationDemo"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:Ursa.Demo.ViewModels"
|
||||
x:DataType="vm:NotificationDemoViewModel"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<Design.DataContext>
|
||||
<vm:NotificationDemoViewModel />
|
||||
</Design.DataContext>
|
||||
<StackPanel>
|
||||
<ToggleSwitch IsChecked="{Binding ShowClose}" Content="ShowClose"/>
|
||||
<StackPanel Orientation="Horizontal" Spacing="20">
|
||||
<Button Command="{Binding ShowNormal}" CommandParameter="{Binding $self.Content}" Content="Information" />
|
||||
<Button Command="{Binding ShowNormal}" CommandParameter="{Binding $self.Content}" Content="Success" Classes="Success" />
|
||||
<Button Command="{Binding ShowNormal}" CommandParameter="{Binding $self.Content}" Content="Warning" Classes="Warning" />
|
||||
<Button Command="{Binding ShowNormal}" CommandParameter="{Binding $self.Content}" Content="Error" Classes="Danger" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Spacing="20">
|
||||
<StackPanel.Styles>
|
||||
<Style Selector="Button">
|
||||
<Setter Property="Theme" Value="{DynamicResource SolidButton}" />
|
||||
</Style>
|
||||
</StackPanel.Styles>
|
||||
<Button Command="{Binding ShowLight}" CommandParameter="{Binding $self.Content}" Content="Information" />
|
||||
<Button Command="{Binding ShowLight}" CommandParameter="{Binding $self.Content}" Content="Success" Classes="Success" />
|
||||
<Button Command="{Binding ShowLight}" CommandParameter="{Binding $self.Content}" Content="Warning" Classes="Warning" />
|
||||
<Button Command="{Binding ShowLight}" CommandParameter="{Binding $self.Content}" Content="Error" Classes="Danger" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
25
demo/Ursa.Demo/Pages/NotificationDemo.axaml.cs
Normal file
25
demo/Ursa.Demo/Pages/NotificationDemo.axaml.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Ursa.Controls;
|
||||
using Ursa.Demo.ViewModels;
|
||||
|
||||
namespace Ursa.Demo.Pages;
|
||||
|
||||
public partial class NotificationDemo : UserControl
|
||||
{
|
||||
private NotificationDemoViewModel _viewModel;
|
||||
|
||||
public NotificationDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
_viewModel = new NotificationDemoViewModel();
|
||||
DataContext = _viewModel;
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
_viewModel.NotificationManager = new WindowNotificationManager(topLevel) { MaxItems = 3 };
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ public class MainViewViewModel : ViewModelBase
|
||||
MenuKeys.MenuKeyMessageBox => new MessageBoxDemoViewModel(),
|
||||
MenuKeys.MenuKeyMultiComboBox => new MultiComboBoxDemoViewModel(),
|
||||
MenuKeys.MenuKeyNavMenu => new NavMenuDemoViewModel(),
|
||||
MenuKeys.MenuKeyNotification => new NotificationDemoViewModel(),
|
||||
MenuKeys.MenuKeyNumberDisplayer => new NumberDisplayerDemoViewModel(),
|
||||
MenuKeys.MenuKeyNumericUpDown => new NumericUpDownDemoViewModel(),
|
||||
MenuKeys.MenuKeyNumPad => new NumPadDemoViewModel(),
|
||||
|
||||
@@ -37,6 +37,7 @@ public class MenuViewModel: ViewModelBase
|
||||
new() { MenuHeader = "Message Box", Key = MenuKeys.MenuKeyMessageBox },
|
||||
new() { MenuHeader = "MultiComboBox", Key = MenuKeys.MenuKeyMultiComboBox, Status = "Updated" },
|
||||
new() { MenuHeader = "Nav Menu", Key = MenuKeys.MenuKeyNavMenu },
|
||||
new() { MenuHeader = "Notification", Key = MenuKeys.MenuKeyNotification },
|
||||
new() { MenuHeader = "Number Displayer", Key = MenuKeys.MenuKeyNumberDisplayer, Status = "New" },
|
||||
new() { MenuHeader = "Numeric UpDown", Key = MenuKeys.MenuKeyNumericUpDown },
|
||||
new() { MenuHeader = "NumPad", Key = MenuKeys.MenuKeyNumPad },
|
||||
@@ -88,6 +89,7 @@ public static class MenuKeys
|
||||
public const string MenuKeyMessageBox = "MessageBox";
|
||||
public const string MenuKeyMultiComboBox = "MultiComboBox";
|
||||
public const string MenuKeyNavMenu = "NavMenu";
|
||||
public const string MenuKeyNotification = "Notification";
|
||||
public const string MenuKeyNumberDisplayer = "NumberDisplayer";
|
||||
public const string MenuKeyNumericUpDown = "NumericUpDown";
|
||||
public const string MenuKeyNumPad = "NumPad";
|
||||
|
||||
42
demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs
Normal file
42
demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using Avalonia.Controls.Notifications;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Notification = Ursa.Controls.Notification;
|
||||
using WindowNotificationManager = Ursa.Controls.WindowNotificationManager;
|
||||
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
|
||||
public partial class NotificationDemoViewModel : ObservableObject
|
||||
{
|
||||
public WindowNotificationManager? NotificationManager { get; set; }
|
||||
|
||||
[ObservableProperty] private bool _showClose = true;
|
||||
|
||||
[RelayCommand]
|
||||
public void ShowNormal(object obj)
|
||||
{
|
||||
if (obj is string s)
|
||||
{
|
||||
Enum.TryParse<NotificationType>(s, out var notificationType);
|
||||
NotificationManager?.Show(
|
||||
new Notification("Welcome", "This is message"),
|
||||
showClose: ShowClose,
|
||||
type: notificationType);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void ShowLight(object obj)
|
||||
{
|
||||
if (obj is string s)
|
||||
{
|
||||
Enum.TryParse<NotificationType>(s, out var notificationType);
|
||||
NotificationManager?.Show(
|
||||
new Notification("Welcome", "This is message"),
|
||||
showClose: ShowClose,
|
||||
type: notificationType,
|
||||
classes: ["Light"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user