0

我希望对话框内容的背景颜色和按钮后面的背景颜色相同:

内容对话框

我怎样才能做到这一点?

我的xml:

<Page
    x:Class="WinUI3BlankAppVS2022.ContentDialogContent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel
        VerticalAlignment="Stretch"
        HorizontalAlignment="Stretch">
        <TextBlock
            Text="Lorem ipsum dolor sit amet, adipisicing elit."
            TextWrapping="Wrap" />
    </StackPanel>
</Page>

我的C#:

private async void ShowDialog_Click(object sender, RoutedEventArgs e)
{
    ContentDialog dialog = new ContentDialog();
    dialog.Title = "Save your work?";
    dialog.PrimaryButtonText = "Save";
    dialog.SecondaryButtonText = "Don't Save";
    dialog.CloseButtonText = "Cancel";
    dialog.DefaultButton = ContentDialogButton.Primary;
    dialog.XamlRoot = Content.XamlRoot;
    dialog.Content = new ContentDialogContent();
    var result = await dialog.ShowAsync();
}
4

1 回答 1

1

我认为解决这个问题的最简单方法是将ContentDialogTopOverlayContentDialogSeparatorBorderBrush主题资源设置为null

private async void ShowDialog_Click(object sender, RoutedEventArgs e)
{
    ContentDialog dialog = new ContentDialog();
    dialog.Title = "Save your work?";
    dialog.PrimaryButtonText = "Save";
    dialog.SecondaryButtonText = "Don't Save";
    dialog.CloseButtonText = "Cancel";
    dialog.DefaultButton = ContentDialogButton.Primary;
    dialog.XamlRoot = Content.XamlRoot;
    Application.Current.Resources["ContentDialogTopOverlay"] = null;
    Application.Current.Resources["ContentDialogSeparatorBorderBrush"] = null;
    dialog.Content = new ContentDialogContent();
    await dialog.ShowAsync();
}

另一种选择是为ContentDialog.

于 2022-01-27T20:38:28.457 回答