Merge pull request #398 from irihitech/toast
New Control: Notification & Toast
This commit is contained in:
@@ -53,6 +53,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(),
|
||||
@@ -68,6 +69,7 @@ public class MainViewViewModel : ViewModelBase
|
||||
MenuKeys.MenuKeyTreeComboBox => new TreeComboBoxDemoViewModel(),
|
||||
MenuKeys.MenuKeyTwoTonePathIcon => new TwoTonePathIconDemoViewModel(),
|
||||
MenuKeys.MenuKeyThemeToggler => new ThemeTogglerDemoViewModel(),
|
||||
MenuKeys.MenuKeyToast => new ToastDemoViewModel(),
|
||||
MenuKeys.MenuKeyToolBar => new ToolBarDemoViewModel(),
|
||||
MenuKeys.MenuKeyTimeBox => new TimeBoxDemoViewModel(),
|
||||
MenuKeys.MenuKeyPinCode => new PinCodeDemoViewModel(),
|
||||
|
||||
@@ -38,6 +38,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, Status = "New"},
|
||||
new() { MenuHeader = "Number Displayer", Key = MenuKeys.MenuKeyNumberDisplayer, Status = "New" },
|
||||
new() { MenuHeader = "Numeric UpDown", Key = MenuKeys.MenuKeyNumericUpDown },
|
||||
new() { MenuHeader = "NumPad", Key = MenuKeys.MenuKeyNumPad },
|
||||
@@ -54,6 +55,7 @@ public class MenuViewModel: ViewModelBase
|
||||
new() { MenuHeader = "Timeline", Key = MenuKeys.MenuKeyTimeline },
|
||||
new() { MenuHeader = "TreeComboBox", Key = MenuKeys.MenuKeyTreeComboBox },
|
||||
new() { MenuHeader = "TwoTonePathIcon", Key = MenuKeys.MenuKeyTwoTonePathIcon},
|
||||
new() { MenuHeader = "Toast", Key = MenuKeys.MenuKeyToast, Status = "New"},
|
||||
new() { MenuHeader = "ToolBar", Key = MenuKeys.MenuKeyToolBar },
|
||||
new() { MenuHeader = "Time Box", Key = MenuKeys.MenuKeyTimeBox },
|
||||
};
|
||||
@@ -89,6 +91,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";
|
||||
@@ -104,6 +107,7 @@ public static class MenuKeys
|
||||
public const string MenuKeyTwoTonePathIcon = "TwoTonePathIcon";
|
||||
public const string MenuKeyThemeToggler = "ThemeToggler";
|
||||
public const string MenuKeyTreeComboBox = "TreeComboBox";
|
||||
public const string MenuKeyToast = "Toast";
|
||||
public const string MenuKeyToolBar = "ToolBar";
|
||||
public const string MenuKeyPinCode = "PinCode";
|
||||
public const string MenuKeyTimeBox = "TimeBox";
|
||||
|
||||
51
demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs
Normal file
51
demo/Ursa.Demo/ViewModels/NotificationDemoViewModel.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
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 _showIcon = true;
|
||||
[ObservableProperty] private bool _showClose = true;
|
||||
|
||||
[RelayCommand]
|
||||
public void ChangePosition(object obj)
|
||||
{
|
||||
if (obj is string s && NotificationManager is not null)
|
||||
{
|
||||
Enum.TryParse<NotificationPosition>(s, out var notificationPosition);
|
||||
NotificationManager.Position = notificationPosition;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void ShowNormal(object obj)
|
||||
{
|
||||
if (obj is not string s) return;
|
||||
Enum.TryParse<NotificationType>(s, out var notificationType);
|
||||
NotificationManager?.Show(
|
||||
new Notification("Welcome", "This is message"),
|
||||
showIcon: ShowIcon,
|
||||
showClose: ShowClose,
|
||||
type: notificationType);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void ShowLight(object obj)
|
||||
{
|
||||
if (obj is not string s) return;
|
||||
Enum.TryParse<NotificationType>(s, out var notificationType);
|
||||
NotificationManager?.Show(
|
||||
new Notification("Welcome", "This is message"),
|
||||
showIcon: ShowIcon,
|
||||
showClose: ShowClose,
|
||||
type: notificationType,
|
||||
classes: ["Light"]);
|
||||
}
|
||||
}
|
||||
64
demo/Ursa.Demo/ViewModels/ToastDemoViewModel.cs
Normal file
64
demo/Ursa.Demo/ViewModels/ToastDemoViewModel.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using Avalonia.Controls.Notifications;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
|
||||
public partial class ToastDemoViewModel : ObservableObject
|
||||
{
|
||||
public WindowToastManager? ToastManager { get; set; }
|
||||
|
||||
[ObservableProperty] private bool _showIcon = true;
|
||||
[ObservableProperty] private bool _showClose = true;
|
||||
|
||||
[RelayCommand]
|
||||
public void ShowNormal(object obj)
|
||||
{
|
||||
if (obj is string s)
|
||||
{
|
||||
Enum.TryParse<NotificationType>(s, out var notificationType);
|
||||
ToastManager?.Show(
|
||||
new Toast("This is message"),
|
||||
showIcon: ShowIcon,
|
||||
showClose: ShowClose,
|
||||
type: notificationType);
|
||||
}
|
||||
|
||||
// ToastManager?.Show(new ToastDemoViewModel
|
||||
// {
|
||||
// Content = "This is message",
|
||||
// ToastManager = ToastManager
|
||||
// });
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void ShowLight(object obj)
|
||||
{
|
||||
if (obj is string s)
|
||||
{
|
||||
Enum.TryParse<NotificationType>(s, out var notificationType);
|
||||
ToastManager?.Show(
|
||||
new Toast("This is message"),
|
||||
showIcon: ShowIcon,
|
||||
showClose: ShowClose,
|
||||
type: notificationType,
|
||||
classes: ["Light"]);
|
||||
}
|
||||
}
|
||||
|
||||
public string? Content { get; set; }
|
||||
|
||||
[RelayCommand]
|
||||
public void YesCommand()
|
||||
{
|
||||
ToastManager?.Show(new Toast("Yes!"));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void NoCommand()
|
||||
{
|
||||
ToastManager?.Show(new Toast("No!"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user