优化更新代码,添加界面功能并整合
This commit is contained in:
48
WPFluent/ContentDialogService.cs
Normal file
48
WPFluent/ContentDialogService.cs
Normal 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"> <ContentPresenter x:Name="RootContentDialogPresenter" Grid.Row="0" /></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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user