如何使内容对话框背景保持一致?
How to make content dialog background consistent?
我希望对话框内容的背景颜色和按钮后面的背景颜色相同:
我该怎么做?
我的xaml:
<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();
}
我认为解决这个问题最简单的方法是将 ContentDialogTopOverlay
和 ContentDialogSeparatorBorderBrush
主题资源设置为 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
创建自定义模板。
我希望对话框内容的背景颜色和按钮后面的背景颜色相同:
我该怎么做?
我的xaml:
<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();
}
我认为解决这个问题最简单的方法是将 ContentDialogTopOverlay
和 ContentDialogSeparatorBorderBrush
主题资源设置为 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
创建自定义模板。