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 badges1 Answer
Reset to default 0You 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.