优化更新代码,添加界面功能并整合

This commit is contained in:
GG Z
2025-02-10 20:53:40 +08:00
parent 83b846f15f
commit 978e03a67f
1389 changed files with 95739 additions and 22200 deletions

View File

@@ -0,0 +1,48 @@
using WPFluent.Controls;
using System.Windows.Controls;
namespace WPFluent;
/// <summary>
/// Represents a contract with the service that creates <see cref="ContentDialog"/>.
/// </summary>
/// <example>
/// <code lang="xml"> &lt;ContentPresenter x:Name="RootContentDialogPresenter" Grid.Row="0" /&gt;</code> <code
/// lang="csharp"> IContentDialogService contentDialogService = new ContentDialogService();
/// contentDialogService.SetContentPresenter(RootContentDialogPresenter); await _contentDialogService.ShowAsync( new
/// ContentDialog(){ Title = "The cake?", Content = "IS A LIE!", PrimaryButtonText = "Save", SecondaryButtonText =
/// "Don't Save", CloseButtonText = "Cancel" } );</code>
/// </example>
public class ContentDialogService : IContentDialogService
{
private ContentPresenter? _dialogHost;
/// <inheritdoc/>
public ContentPresenter? GetDialogHost() { return _dialogHost; }
/// <inheritdoc/>
public void SetDialogHost(ContentPresenter contentPresenter) { _dialogHost = contentPresenter; }
/// <inheritdoc/>
public Task<ContentDialogResult> ShowAsync(ContentDialog dialog, CancellationToken cancellationToken)
{
if (_dialogHost == null)
{
throw new InvalidOperationException("The DialogHost was never set.");
}
if (dialog.DialogHost != null && _dialogHost != dialog.DialogHost)
{
throw new InvalidOperationException("The DialogHost is not the same as the one that was previously set.");
}
dialog.DialogHost = _dialogHost;
return dialog.ShowAsync(cancellationToken);
}
}