feat: Notification Position.
This commit is contained in:
@@ -11,24 +11,50 @@
|
||||
<Design.DataContext>
|
||||
<vm:NotificationDemoViewModel />
|
||||
</Design.DataContext>
|
||||
<StackPanel>
|
||||
<ToggleSwitch IsChecked="{Binding ShowClose}" Content="ShowClose"/>
|
||||
<StackPanel Spacing="20">
|
||||
<ToggleSwitch IsChecked="{Binding ShowClose}" Content="ShowClose" />
|
||||
|
||||
<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">
|
||||
<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.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 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" />
|
||||
<Button Content="Information" />
|
||||
<Button Content="Success" Classes="Success" />
|
||||
<Button Content="Warning" Classes="Warning" />
|
||||
<Button Content="Error" Classes="Danger" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -11,24 +11,34 @@
|
||||
<Design.DataContext>
|
||||
<vm:ToastDemoViewModel />
|
||||
</Design.DataContext>
|
||||
<StackPanel>
|
||||
<ToggleSwitch IsChecked="{Binding ShowClose}" Content="ShowClose"/>
|
||||
<StackPanel Spacing="20">
|
||||
<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.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 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" />
|
||||
<Button Content="Information" />
|
||||
<Button Content="Success" Classes="Success" />
|
||||
<Button Content="Warning" Classes="Warning" />
|
||||
<Button Content="Error" Classes="Danger" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -13,6 +13,16 @@ public partial class NotificationDemoViewModel : ObservableObject
|
||||
|
||||
[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)
|
||||
{
|
||||
|
||||
@@ -22,8 +22,36 @@
|
||||
<ReversibleStackPanel Name="PART_Items" />
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
<Style Selector="^ /template/ ReversibleStackPanel#PART_Items">
|
||||
<Style Selector="^:topleft /template/ ReversibleStackPanel#PART_Items">
|
||||
<Setter Property="VerticalAlignment" Value="Top" />
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="^:topright /template/ ReversibleStackPanel#PART_Items">
|
||||
<Setter Property="VerticalAlignment" Value="Top" />
|
||||
<Setter Property="HorizontalAlignment" Value="Right" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="^:topcenter /template/ ReversibleStackPanel#PART_Items">
|
||||
<Setter Property="VerticalAlignment" Value="Top" />
|
||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="^:bottomleft /template/ ReversibleStackPanel#PART_Items">
|
||||
<Setter Property="ReverseOrder" Value="True" />
|
||||
<Setter Property="VerticalAlignment" Value="Bottom" />
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="^:bottomright /template/ ReversibleStackPanel#PART_Items">
|
||||
<Setter Property="ReverseOrder" Value="True" />
|
||||
<Setter Property="VerticalAlignment" Value="Bottom" />
|
||||
<Setter Property="HorizontalAlignment" Value="Right" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="^:bottomcenter /template/ ReversibleStackPanel#PART_Items">
|
||||
<Setter Property="ReverseOrder" Value="True" />
|
||||
<Setter Property="VerticalAlignment" Value="Bottom" />
|
||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||
</Style>
|
||||
</ControlTheme>
|
||||
|
||||
@@ -1,6 +1,40 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Notifications;
|
||||
using Avalonia.LogicalTree;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Control that represents and displays a notification.
|
||||
/// </summary>
|
||||
public class NotificationCard : MessageCard;
|
||||
public class NotificationCard : MessageCard
|
||||
{
|
||||
private NotificationPosition _position;
|
||||
|
||||
public NotificationPosition Position
|
||||
{
|
||||
get => _position;
|
||||
set => SetAndRaise(PositionProperty, ref _position, value);
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<NotificationCard, NotificationPosition> PositionProperty =
|
||||
AvaloniaProperty.RegisterDirect<NotificationCard, NotificationPosition>(nameof(Position),
|
||||
o => o.Position, (o, v) => o.Position = v);
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
UpdatePseudoClasses(Position);
|
||||
}
|
||||
|
||||
private void UpdatePseudoClasses(NotificationPosition position)
|
||||
{
|
||||
PseudoClasses.Set(WindowNotificationManager.PC_TopLeft, position == NotificationPosition.TopLeft);
|
||||
PseudoClasses.Set(WindowNotificationManager.PC_TopRight, position == NotificationPosition.TopRight);
|
||||
PseudoClasses.Set(WindowNotificationManager.PC_BottomLeft, position == NotificationPosition.BottomLeft);
|
||||
PseudoClasses.Set(WindowNotificationManager.PC_BottomRight, position == NotificationPosition.BottomRight);
|
||||
PseudoClasses.Set(WindowNotificationManager.PC_TopCenter, position == NotificationPosition.TopCenter);
|
||||
PseudoClasses.Set(WindowNotificationManager.PC_BottomCenter, position == NotificationPosition.BottomCenter);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user