Merge pull request #398 from irihitech/toast

New Control: Notification & Toast
This commit is contained in:
Dong Bin
2024-09-12 18:55:40 +08:00
committed by GitHub
33 changed files with 2034 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
<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 Spacing="20">
<StackPanel Orientation="Horizontal">
<ToggleSwitch IsChecked="{Binding ShowIcon}" Content="ShowIcon" />
<ToggleSwitch IsChecked="{Binding ShowClose}" Content="ShowClose" />
</StackPanel>
<UniformGrid Rows="2" Columns="3" Width="500" HorizontalAlignment="Left">
<UniformGrid.Styles>
<Style Selector="RadioButton">
<Setter Property="Theme" Value="{DynamicResource PureCardRadioButton}" />
<Setter Property="Command" Value="{Binding ChangePosition}" />
<Setter Property="CommandParameter" Value="{Binding $self.Content}" />
</Style>
</UniformGrid.Styles>
<RadioButton Content="TopLeft" />
<RadioButton Content="TopCenter" />
<RadioButton Content="TopRight" IsChecked="True" />
<RadioButton Content="BottomLeft" />
<RadioButton Content="BottomCenter" />
<RadioButton Content="BottomRight" />
</UniformGrid>
<StackPanel Orientation="Horizontal" Spacing="20">
<StackPanel.Styles>
<Style Selector="Button">
<Setter Property="Command" Value="{Binding ShowNormal}" />
<Setter Property="CommandParameter" Value="{Binding $self.Content}" />
</Style>
</StackPanel.Styles>
<Button Content="Information" />
<Button Content="Success" Classes="Success" />
<Button Content="Warning" Classes="Warning" />
<Button Content="Error" Classes="Danger" />
</StackPanel>
<StackPanel Orientation="Horizontal" Spacing="20">
<StackPanel.Styles>
<Style Selector="Button">
<Setter Property="Theme" Value="{DynamicResource SolidButton}" />
<Setter Property="Command" Value="{Binding ShowLight}" />
<Setter Property="CommandParameter" Value="{Binding $self.Content}" />
</Style>
</StackPanel.Styles>
<Button Content="Information" />
<Button Content="Success" Classes="Success" />
<Button Content="Warning" Classes="Warning" />
<Button Content="Error" Classes="Danger" />
</StackPanel>
</StackPanel>
</UserControl>

View File

@@ -0,0 +1,32 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.LogicalTree;
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 };
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
_viewModel.NotificationManager?.Uninstall();
}
}

View File

@@ -0,0 +1,47 @@
<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 Spacing="20">
<StackPanel Orientation="Horizontal">
<ToggleSwitch IsChecked="{Binding ShowIcon}" Content="ShowIcon" />
<ToggleSwitch IsChecked="{Binding ShowClose}" Content="ShowClose" />
</StackPanel>
<StackPanel Orientation="Horizontal" Spacing="20">
<StackPanel.Styles>
<Style Selector="Button">
<Setter Property="Command" Value="{Binding ShowNormal}" />
<Setter Property="CommandParameter" Value="{Binding $self.Content}" />
</Style>
</StackPanel.Styles>
<Button Content="Information" />
<Button Content="Success" Classes="Success" />
<Button Content="Warning" Classes="Warning" />
<Button Content="Error" Classes="Danger" />
</StackPanel>
<StackPanel Orientation="Horizontal" Spacing="20">
<StackPanel.Styles>
<Style Selector="Button">
<Setter Property="Theme" Value="{DynamicResource SolidButton}" />
<Setter Property="Command" Value="{Binding ShowLight}" />
<Setter Property="CommandParameter" Value="{Binding $self.Content}" />
</Style>
</StackPanel.Styles>
<Button Content="Information" />
<Button Content="Success" Classes="Success" />
<Button Content="Warning" Classes="Warning" />
<Button Content="Error" Classes="Danger" />
</StackPanel>
</StackPanel>
</UserControl>

View File

@@ -0,0 +1,31 @@
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 };
}
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
_viewModel.ToastManager?.Uninstall();
}
}