using WPFluent.Controls; using System.Windows.Controls; namespace WPFluent; /// /// Represents a contract with the service that creates . /// /// /// <ContentPresenter x:Name="RootContentDialogPresenter" Grid.Row="0" /> 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" } ); /// public class ContentDialogService : IContentDialogService { private ContentPresenter? _dialogHost; /// public ContentPresenter? GetDialogHost() { return _dialogHost; } /// public void SetDialogHost(ContentPresenter contentPresenter) { _dialogHost = contentPresenter; } /// public Task 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); } }