如何 blocked/Inactivate Uwp app title bar due to show ContentDialog?
How to blocked/Inactivate Uwp app title bar due to show ContentDialog?
由于显示 ContentDialog,我需要 blocked/Inactivate 带有标题栏的整个 Uwp 应用程序。我使用了 Microsoft XAML Controls Gallery App 的代码,而 Control-Gallery 应用程序正确阻止了整个应用程序,但我的测试应用程序没有阻止该应用程序。
这是在资源字典中添加 winui:XamlControlsResources ControlsResourcesVersion="Version2"
之后的另一个屏幕截图。这也可以通过覆盖 SystemControlPageBackgroundMediumAltMediumBrush
.
来实现
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="#000000" Opacity="0.18"/>
或
<Application
x:Class="App2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App2"
xmlns:winui="using:Microsoft.UI.Xaml.Controls">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<winui:XamlControlsResources ControlsResourcesVersion="Version2" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
这里是使用的示例代码:
<Page
x:Class="App2.ContentDialogContent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<!-- Content body -->
<TextBlock Text="Lorem ipsum dolor sit amet, adipisicing elit." TextWrapping="Wrap" />
<CheckBox Content="Upload your content to the cloud." />
</StackPanel>
</Page>
按钮点击:
private async void button_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.Content = new ContentDialogContent();
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
//DialogResult.Text = "User saved their work";
}
else if (result == ContentDialogResult.Secondary)
{
//DialogResult.Text = "User did not save their work";
}
else
{
//DialogResult.Text = "User cancelled the dialog";
}
}
我已经使用了ExtendViewIntoTitleBar
,但问题仍然存在于标题栏的系统按钮区域
正如 Rufo 爵士所说,您的预期视图已设置 ExtendViewIntoTitleBar
为真,可以将您的视图内容扩展到标题栏中。它可以使整个当前视图内容被 ContentDialog
.
阻塞
使用 ExtendViewIntoTitleBar
, please refer to Title bar customization.
var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;
更新
您需要将标题栏按钮的背景颜色设置为透明。
ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
titleBar.ButtonBackgroundColor = Colors.Transparent;
由于显示 ContentDialog,我需要 blocked/Inactivate 带有标题栏的整个 Uwp 应用程序。我使用了 Microsoft XAML Controls Gallery App 的代码,而 Control-Gallery 应用程序正确阻止了整个应用程序,但我的测试应用程序没有阻止该应用程序。
这是在资源字典中添加 winui:XamlControlsResources ControlsResourcesVersion="Version2"
之后的另一个屏幕截图。这也可以通过覆盖 SystemControlPageBackgroundMediumAltMediumBrush
.
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="#000000" Opacity="0.18"/>
或
<Application
x:Class="App2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App2"
xmlns:winui="using:Microsoft.UI.Xaml.Controls">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<winui:XamlControlsResources ControlsResourcesVersion="Version2" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
这里是使用的示例代码:
<Page
x:Class="App2.ContentDialogContent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<!-- Content body -->
<TextBlock Text="Lorem ipsum dolor sit amet, adipisicing elit." TextWrapping="Wrap" />
<CheckBox Content="Upload your content to the cloud." />
</StackPanel>
</Page>
按钮点击:
private async void button_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.Content = new ContentDialogContent();
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
//DialogResult.Text = "User saved their work";
}
else if (result == ContentDialogResult.Secondary)
{
//DialogResult.Text = "User did not save their work";
}
else
{
//DialogResult.Text = "User cancelled the dialog";
}
}
我已经使用了ExtendViewIntoTitleBar
,但问题仍然存在于标题栏的系统按钮区域
正如 Rufo 爵士所说,您的预期视图已设置 ExtendViewIntoTitleBar
为真,可以将您的视图内容扩展到标题栏中。它可以使整个当前视图内容被 ContentDialog
.
使用 ExtendViewIntoTitleBar
, please refer to Title bar customization.
var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;
更新
您需要将标题栏按钮的背景颜色设置为透明。
ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
titleBar.ButtonBackgroundColor = Colors.Transparent;