feat: enhance PopConfirm with async command support and improve binding. add more demo.
This commit is contained in:
@@ -9,9 +9,23 @@
|
|||||||
x:DataType="viewModels:PopConfirmDemoViewModel"
|
x:DataType="viewModels:PopConfirmDemoViewModel"
|
||||||
x:Class="Ursa.Demo.Pages.PopConfirmDemo">
|
x:Class="Ursa.Demo.Pages.PopConfirmDemo">
|
||||||
<StackPanel HorizontalAlignment="Left">
|
<StackPanel HorizontalAlignment="Left">
|
||||||
|
<TextBlock Text="Default PopConfirm" Margin="0 16" />
|
||||||
<u:PopConfirm PopupHeader="Header" PopupContent="Content"
|
<u:PopConfirm PopupHeader="Header" PopupContent="Content"
|
||||||
ConfirmCommand="{Binding ConfirmCommand}"
|
ConfirmCommand="{Binding ConfirmCommand}"
|
||||||
CancelCommand="{Binding Path=CancelCommand}" >
|
CancelCommand="{Binding Path=CancelCommand}" >
|
||||||
|
<Button Content="Hello World"></Button>
|
||||||
|
</u:PopConfirm>
|
||||||
|
<TextBlock Text="Hover to trigger" Margin="0 16" />
|
||||||
|
<u:PopConfirm PopupHeader="Header" PopupContent="Content"
|
||||||
|
TriggerMode="Focus"
|
||||||
|
ConfirmCommand="{Binding ConfirmCommand}"
|
||||||
|
CancelCommand="{Binding Path=CancelCommand}" >
|
||||||
|
<Button Content="Hello World"></Button>
|
||||||
|
</u:PopConfirm>
|
||||||
|
<TextBlock Text="Asynchronized command support" Margin="0 16" />
|
||||||
|
<u:PopConfirm PopupHeader="Header" PopupContent="Content"
|
||||||
|
ConfirmCommand="{Binding AsyncConfirmCommand}"
|
||||||
|
CancelCommand="{Binding Path=AsyncCancelCommand}" >
|
||||||
<Button Content="Hello World"></Button>
|
<Button Content="Hello World"></Button>
|
||||||
</u:PopConfirm>
|
</u:PopConfirm>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -7,27 +7,42 @@ using Ursa.Controls;
|
|||||||
|
|
||||||
namespace Ursa.Demo.ViewModels;
|
namespace Ursa.Demo.ViewModels;
|
||||||
|
|
||||||
public partial class PopConfirmDemoViewModel: ObservableObject
|
public class PopConfirmDemoViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
internal WindowToastManager? ToastManager { get; set; }
|
|
||||||
|
|
||||||
public ICommand ConfirmCommand { get; }
|
|
||||||
public ICommand CancelCommand { get; }
|
|
||||||
|
|
||||||
public PopConfirmDemoViewModel()
|
public PopConfirmDemoViewModel()
|
||||||
{
|
{
|
||||||
ConfirmCommand = new AsyncRelayCommand(OnConfirm);
|
AsyncConfirmCommand = new AsyncRelayCommand(OnConfirmAsync);
|
||||||
|
AsyncCancelCommand = new RelayCommand(OnCancelAsync);
|
||||||
|
ConfirmCommand = new RelayCommand(OnConfirm);
|
||||||
CancelCommand = new RelayCommand(OnCancel);
|
CancelCommand = new RelayCommand(OnCancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnConfirm()
|
internal WindowToastManager? ToastManager { get; set; }
|
||||||
{
|
|
||||||
await Task.Delay(3000);
|
public ICommand ConfirmCommand { get; }
|
||||||
ToastManager?.Show(new Toast("Confirmed"), type: NotificationType.Success, classes: ["Light"]);
|
public ICommand CancelCommand { get; }
|
||||||
}
|
|
||||||
|
public ICommand AsyncConfirmCommand { get; }
|
||||||
|
public ICommand AsyncCancelCommand { get; }
|
||||||
|
|
||||||
private void OnCancel()
|
private void OnCancel()
|
||||||
{
|
{
|
||||||
ToastManager?.Show(new Toast("Canceled"), type:NotificationType.Error, classes: ["Light"]);
|
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"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
ContentTemplate="{TemplateBinding ContentTemplate}" />
|
ContentTemplate="{TemplateBinding ContentTemplate}" />
|
||||||
<Popup
|
<Popup
|
||||||
IsLightDismissEnabled="True"
|
IsLightDismissEnabled="True"
|
||||||
IsOpen="{TemplateBinding IsDropdownOpen, Mode=TwoWay}"
|
IsOpen="{Binding IsDropdownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
|
||||||
OverlayInputPassThroughElement="{Binding #PART_ContentPresenter}"
|
OverlayInputPassThroughElement="{Binding #PART_ContentPresenter}"
|
||||||
Name="{x:Static u:PopConfirm.PART_Popup}"
|
Name="{x:Static u:PopConfirm.PART_Popup}"
|
||||||
Placement="{TemplateBinding Placement}" >
|
Placement="{TemplateBinding Placement}" >
|
||||||
|
|||||||
@@ -201,8 +201,11 @@ public class PopConfirm : ContentControl
|
|||||||
protected override bool RegisterContentPresenter(ContentPresenter presenter)
|
protected override bool RegisterContentPresenter(ContentPresenter presenter)
|
||||||
{
|
{
|
||||||
var result = base.RegisterContentPresenter(presenter);
|
var result = base.RegisterContentPresenter(presenter);
|
||||||
_childChangeDisposable = presenter.GetPropertyChangedObservable(ContentPresenter.ChildProperty)
|
if (result)
|
||||||
.Subscribe(OnChildChanged);
|
{
|
||||||
|
_childChangeDisposable = presenter.GetPropertyChangedObservable(ContentPresenter.ChildProperty)
|
||||||
|
.Subscribe(OnChildChanged);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user