feat: add new Toast.
This commit is contained in:
33
demo/Ursa.Demo/Pages/ToastDemo.axaml
Normal file
33
demo/Ursa.Demo/Pages/ToastDemo.axaml
Normal file
@@ -0,0 +1,33 @@
|
||||
<UserControl x:Class="Ursa.Demo.Pages.ToastDemo"
|
||||
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:ToastDemoViewModel"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<Design.DataContext>
|
||||
<vm:ToastDemoViewModel />
|
||||
</Design.DataContext>
|
||||
<StackPanel>
|
||||
<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/ToastDemo.axaml.cs
Normal file
25
demo/Ursa.Demo/Pages/ToastDemo.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 ToastDemo : UserControl
|
||||
{
|
||||
private ToastDemoViewModel _viewModel;
|
||||
|
||||
public ToastDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
_viewModel = new ToastDemoViewModel();
|
||||
DataContext = _viewModel;
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
_viewModel.ToastManager = new WindowToastManager(topLevel) { MaxItems = 3 };
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,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(),
|
||||
|
||||
@@ -53,6 +53,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 },
|
||||
new() { MenuHeader = "ToolBar", Key = MenuKeys.MenuKeyToolBar },
|
||||
new() { MenuHeader = "Time Box", Key = MenuKeys.MenuKeyTimeBox },
|
||||
};
|
||||
@@ -102,6 +103,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";
|
||||
|
||||
57
demo/Ursa.Demo/ViewModels/ToastDemoViewModel.cs
Normal file
57
demo/Ursa.Demo/ViewModels/ToastDemoViewModel.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
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; }
|
||||
|
||||
[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"),
|
||||
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"),
|
||||
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