change - 删除时添加确认界面
parent
fef4b32c41
commit
0a8fcbf4df
@ -0,0 +1,50 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="Sln.Wcs.UI.Views.Base.ConfirmDialog"
|
||||
x:CompileBindings="False"
|
||||
Title="确认操作"
|
||||
SizeToContent="WidthAndHeight"
|
||||
MaxWidth="380"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
CanResize="False"
|
||||
Background="Transparent"
|
||||
ExtendClientAreaToDecorationsHint="True"
|
||||
ExtendClientAreaChromeHints="PreferSystemChrome"
|
||||
SystemDecorations="Full">
|
||||
|
||||
<Border Background="{DynamicResource SurfaceBgBrush}" CornerRadius="10"
|
||||
BorderBrush="{DynamicResource AccentBgBrush}" BorderThickness="1">
|
||||
<Grid RowDefinitions="Auto,*,Auto" Margin="0" MinWidth="300">
|
||||
<!-- Title -->
|
||||
<Border Grid.Row="0" Padding="20,14" CornerRadius="10,10,0,0"
|
||||
Background="{DynamicResource CardBgBrush}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="0,0,0,1">
|
||||
<StackPanel Orientation="Horizontal" Spacing="10">
|
||||
<Rectangle Width="3" Height="18" Fill="#FFB74D" RadiusX="2" RadiusY="2" />
|
||||
<TextBlock x:Name="TitleText" Text="确认操作" FontSize="15" FontWeight="SemiBold" Foreground="{DynamicResource PrimaryTextBrush}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- Message -->
|
||||
<StackPanel Grid.Row="1" Margin="24,20,24,16">
|
||||
<TextBlock x:Name="MessageText" Text="" FontSize="13"
|
||||
Foreground="{DynamicResource SecondaryTextBrush}" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Buttons -->
|
||||
<Border Grid.Row="2" Padding="20,12" CornerRadius="0,0,10,10"
|
||||
Background="{DynamicResource PageBgBrush}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="0,1,0,0">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">
|
||||
<Button x:Name="CancelBtn" Content="取 消"
|
||||
FontSize="12" Padding="24,8"
|
||||
Background="{DynamicResource PrimaryBgBrush}" Foreground="{DynamicResource SecondaryTextBrush}"
|
||||
BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1"
|
||||
CornerRadius="4" />
|
||||
<Button x:Name="ConfirmBtn" Content="确 认"
|
||||
FontSize="12" Padding="24,8"
|
||||
Background="{DynamicResource DangerBtnBrush}" Foreground="White"
|
||||
CornerRadius="4" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Window>
|
||||
@ -0,0 +1,31 @@
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Sln.Wcs.UI.Views.Base;
|
||||
|
||||
public partial class ConfirmDialog : Window
|
||||
{
|
||||
private TaskCompletionSource<bool>? _tcs;
|
||||
|
||||
public ConfirmDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
CancelBtn.Click += (_, _) => CloseWith(false);
|
||||
ConfirmBtn.Click += (_, _) => CloseWith(true);
|
||||
}
|
||||
|
||||
public Task<bool> ShowDialog(string message, Window owner, string title = "确认操作")
|
||||
{
|
||||
TitleText.Text = title;
|
||||
MessageText.Text = message;
|
||||
_tcs = new TaskCompletionSource<bool>();
|
||||
ShowDialog(owner);
|
||||
return _tcs.Task;
|
||||
}
|
||||
|
||||
private void CloseWith(bool result)
|
||||
{
|
||||
_tcs?.TrySetResult(result);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue