最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

winui 3 - Customize the Content dialog in Winui3 to have cancel link in footer - Stack Overflow

programmeradmin4浏览0评论

I am using winui3 unpackaged application. I have startupwindow.xaml.cs where I am asking user to enter their azure credentials. The Interactive browser credential window is launched to choose their account. If user closes the browser window without authenticating, then I am displaying content dialog with Retry and Cancel button. Retry button being primary button when pressed it relaunches browser credentials for user to reauthenticate but when Cancel button clicked the application will close. The content dialog has Retry and Cancel button, but I am trying to customize the content dialog to have Cancel button as link rather than button. I did try couple of options, but nothing worked out and I also read that you can't customize the content dialog buttons.

I need some ideas or some examples on showing content dialog that can have Retry and cancel links in footer section.

I am using winui3 unpackaged application. I have startupwindow.xaml.cs where I am asking user to enter their azure credentials. The Interactive browser credential window is launched to choose their account. If user closes the browser window without authenticating, then I am displaying content dialog with Retry and Cancel button. Retry button being primary button when pressed it relaunches browser credentials for user to reauthenticate but when Cancel button clicked the application will close. The content dialog has Retry and Cancel button, but I am trying to customize the content dialog to have Cancel button as link rather than button. I did try couple of options, but nothing worked out and I also read that you can't customize the content dialog buttons.

I need some ideas or some examples on showing content dialog that can have Retry and cancel links in footer section.

Share asked Mar 17 at 17:41 user3766691user3766691 1811 gold badge3 silver badges7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can create a custom ContentDialog:

public partial class CustomContentDialog : ContentDialog
{
    protected override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        if (this.FindDescendant<Grid>(x => x.Name == "CommandSpace") is Grid commandSpace)
        {
            HyperlinkButton cancelHyperlinkButton = new()
            {
                NavigateUri = new Uri("https://www.google"),
                Content = "Cancel",
            };

            commandSpace.Children.Insert(0, cancelHyperlinkButton);
        }
    }
}

and use it:

var dialog = new CustomContentDialog
{
    Title = "Title",
    Content = "Content",
    CloseButtonText = "Close",
    XamlRoot = this.XamlRoot,
};

await dialog.ShowAsync();
  • You can find the CommandSpace Grid in the generic.xaml file.
  • FindDescendant() comes from the CommunityToolkit.WinUI.Extensions NuGet package.
发布评论

评论列表(0)

  1. 暂无评论