Merge pull request #657 from irihitech/popconfirm
New Control: PopConfirm
This commit is contained in:
72
demo/Ursa.Demo/Pages/PopConfirmDemo.axaml
Normal file
72
demo/Ursa.Demo/Pages/PopConfirmDemo.axaml
Normal file
@@ -0,0 +1,72 @@
|
||||
<UserControl 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:u="https://irihi.tech/ursa"
|
||||
xmlns:viewModels="clr-namespace:Ursa.Demo.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="800"
|
||||
d:DesignHeight="450"
|
||||
x:DataType="viewModels:PopConfirmDemoViewModel"
|
||||
x:Class="Ursa.Demo.Pages.PopConfirmDemo">
|
||||
<StackPanel HorizontalAlignment="Left">
|
||||
<Border Theme="{DynamicResource CardBorder}">
|
||||
<u:Form>
|
||||
<u:ControlClassesInput
|
||||
Name="classInput"
|
||||
u:FormItem.Label="Control Classes"
|
||||
Width="240">
|
||||
</u:ControlClassesInput>
|
||||
<u:EnumSelector
|
||||
Name="placement"
|
||||
Width="240"
|
||||
u:FormItem.Label="Popup Placement"
|
||||
EnumType="{x:Type PlacementMode}"
|
||||
Value="{x:Static PlacementMode.BottomEdgeAlignedLeft}" />
|
||||
</u:Form>
|
||||
</Border>
|
||||
<TextBlock Text="Default PopConfirm" Margin="0 16" />
|
||||
<u:PopConfirm PopupHeader="确定是否要保存此修改?"
|
||||
HorizontalAlignment="Left"
|
||||
PopupContent="此修改将不可逆"
|
||||
Placement="{Binding #placement.Value}"
|
||||
ConfirmCommand="{Binding ConfirmCommand}"
|
||||
CancelCommand="{Binding Path=CancelCommand}">
|
||||
<Button Content="Hello World" />
|
||||
</u:PopConfirm>
|
||||
<TextBlock Text="GotFocus to open, LostFocus to close" Margin="0 16" />
|
||||
<u:PopConfirm PopupHeader="确定是否要保存此修改?"
|
||||
PopupContent="此修改将不可逆"
|
||||
TriggerMode="Focus, Click"
|
||||
HorizontalAlignment="Left"
|
||||
Placement="{Binding #placement.Value}"
|
||||
u:ControlClassesInput.Source="{Binding #classInput}"
|
||||
ConfirmCommand="{Binding ConfirmCommand}"
|
||||
CancelCommand="{Binding Path=CancelCommand}">
|
||||
<Button Content="Hello World" />
|
||||
</u:PopConfirm>
|
||||
<TextBlock
|
||||
Text="Non-button control as main element"
|
||||
Margin="0 16" />
|
||||
<u:PopConfirm PopupHeader="确定是否要保存此修改?"
|
||||
PopupContent="此修改将不可逆"
|
||||
TriggerMode="Click"
|
||||
HorizontalAlignment="Left"
|
||||
u:ControlClassesInput.Source="{Binding #classInput}"
|
||||
Placement="{Binding #placement.Value}"
|
||||
ConfirmCommand="{Binding ConfirmCommand}"
|
||||
CancelCommand="{Binding Path=CancelCommand}">
|
||||
<TextBlock Text="Hello World" />
|
||||
</u:PopConfirm>
|
||||
<TextBlock Text="Asynchronized command support"
|
||||
Margin="0 16" />
|
||||
<u:PopConfirm PopupHeader="确定是否要保存此修改?"
|
||||
PopupContent="此修改将不可逆"
|
||||
HorizontalAlignment="Left"
|
||||
Placement="{Binding #placement.Value}"
|
||||
u:ControlClassesInput.Source="{Binding #classInput}"
|
||||
ConfirmCommand="{Binding AsyncConfirmCommand}"
|
||||
CancelCommand="{Binding Path=AsyncCancelCommand}">
|
||||
<Button Content="Hello World" />
|
||||
</u:PopConfirm>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
25
demo/Ursa.Demo/Pages/PopConfirmDemo.axaml.cs
Normal file
25
demo/Ursa.Demo/Pages/PopConfirmDemo.axaml.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Ursa.Controls;
|
||||
using Ursa.Demo.ViewModels;
|
||||
|
||||
namespace Ursa.Demo.Pages;
|
||||
|
||||
public partial class PopConfirmDemo : UserControl
|
||||
{
|
||||
public PopConfirmDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
if (this.DataContext is not PopConfirmDemoViewModel vm) return;
|
||||
var manager = WindowToastManager.TryGetToastManager(TopLevel.GetTopLevel(this), out var m)
|
||||
? m
|
||||
: new WindowToastManager(TopLevel.GetTopLevel(this));
|
||||
vm.ToastManager = manager;
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,7 @@ public partial class MainViewViewModel : ViewModelBase
|
||||
MenuKeys.MenuKeyNumPad => new NumPadDemoViewModel(),
|
||||
MenuKeys.MenuKeyPagination => new PaginationDemoViewModel(),
|
||||
MenuKeys.MenuKeyPinCode => new PinCodeDemoViewModel(),
|
||||
MenuKeys.MenuKeyPopConfirm => new PopConfirmDemoViewModel(),
|
||||
MenuKeys.MenuKeyRangeSlider => new RangeSliderDemoViewModel(),
|
||||
MenuKeys.MenuKeyRating => new RatingDemoViewModel(),
|
||||
MenuKeys.MenuKeyScrollToButton => new ScrollToButtonDemoViewModel(),
|
||||
|
||||
@@ -44,6 +44,7 @@ public class MenuViewModel : ViewModelBase
|
||||
new() { MenuHeader = "Loading", Key = MenuKeys.MenuKeyLoading, Status = "Updated" },
|
||||
new() { MenuHeader = "Message Box", Key = MenuKeys.MenuKeyMessageBox },
|
||||
new() { MenuHeader = "Notification", Key = MenuKeys.MenuKeyNotification },
|
||||
new() { MenuHeader = "PopConfirm", Key = MenuKeys.MenuKeyPopConfirm },
|
||||
new() { MenuHeader = "Toast", Key = MenuKeys.MenuKeyToast },
|
||||
new() { MenuHeader = "Skeleton", Key = MenuKeys.MenuKeySkeleton },
|
||||
}
|
||||
@@ -135,6 +136,7 @@ public static class MenuKeys
|
||||
public const string MenuKeyNumPad = "NumPad";
|
||||
public const string MenuKeyPagination = "Pagination";
|
||||
public const string MenuKeyPinCode = "PinCode";
|
||||
public const string MenuKeyPopConfirm = "PopConfirm";
|
||||
public const string MenuKeyRangeSlider = "RangeSlider";
|
||||
public const string MenuKeyRating = "Rating";
|
||||
public const string MenuKeyScrollToButton = "ScrollToButton";
|
||||
|
||||
48
demo/Ursa.Demo/ViewModels/PopConfirmDemoViewModel.cs
Normal file
48
demo/Ursa.Demo/ViewModels/PopConfirmDemoViewModel.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Avalonia.Controls.Notifications;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
|
||||
public class PopConfirmDemoViewModel : ObservableObject
|
||||
{
|
||||
public PopConfirmDemoViewModel()
|
||||
{
|
||||
AsyncConfirmCommand = new AsyncRelayCommand(OnConfirmAsync);
|
||||
AsyncCancelCommand = new RelayCommand(OnCancelAsync);
|
||||
ConfirmCommand = new RelayCommand(OnConfirm);
|
||||
CancelCommand = new RelayCommand(OnCancel);
|
||||
}
|
||||
|
||||
internal WindowToastManager? ToastManager { get; set; }
|
||||
|
||||
public ICommand ConfirmCommand { get; }
|
||||
public ICommand CancelCommand { get; }
|
||||
|
||||
public ICommand AsyncConfirmCommand { get; }
|
||||
public ICommand AsyncCancelCommand { get; }
|
||||
|
||||
private void OnCancel()
|
||||
{
|
||||
ToastManager?.Show(new Toast("Canceled"), NotificationType.Error, classes: ["Light"]);
|
||||
}
|
||||
|
||||
private void OnConfirm()
|
||||
{
|
||||
ToastManager?.Show(new Toast("Confirmed"), NotificationType.Success, classes: ["Light"]);
|
||||
}
|
||||
|
||||
private async Task OnConfirmAsync()
|
||||
{
|
||||
await Task.Delay(3000);
|
||||
ToastManager?.Show(new Toast("Async Confirmed"), NotificationType.Success, classes: ["Light"]);
|
||||
}
|
||||
|
||||
private void OnCancelAsync()
|
||||
{
|
||||
ToastManager?.Show(new Toast("Async Canceled"), NotificationType.Error, classes: ["Light"]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user