【问题标题】:UWP ContentDialog covers whole pageUWP ContentDialog 覆盖整个页面
【发布时间】:2020-08-30 10:54:18
【问题描述】:

ContentDialogFluent XAML Theme Editor 的颜色主题一起使用时,内容对话框会覆盖整个页面

要复制,请按以下步骤操作:

  1. 创建新的 UWP 应用
  2. Fluent XAML Theme Editor 获取配色方案并将其添加到您的项目中
  3. 在 App.Xaml 中添加:
     <Application.Resources>
      <ResourceDictionary>
       <ResourceDictionary.MergedDictionaries>
           <ResourceDictionary Source="Dictionary1.xaml"/>
      </ResourceDictionary.MergedDictionaries>
     </ResourceDictionary>
    </Application.Resources>
  1. TextBlockLoaded 事件添加到MainPage
  2. ContentDialog 调用添加到Loaded 事件
   private async void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            ContentDialog noWifiDialog = new ContentDialog
            {
                Title = "No wifi connection",
                Content = "Check your connection and try again.",
                CloseButtonText = "Ok"
            };

            _ = await noWifiDialog.ShowAsync();
        }
  1. 运行应用程序,看看ContentDialog 是如何掩盖TextBlock 的。如果您移除颜色主题,则不会发生这种情况。

【问题讨论】:

    标签: c# xaml uwp themes


    【解决方案1】:

    您所描述的不是覆盖任何东西的对话框,而是Content Dialog 框的正常背景变暗功能。

    Fluent XAML 主题编辑器输出只是更改了样式,使默认背景成为纯色,在我的主题中是白色的,但我希望用户仍能看到背景中的内容。

    这是您需要管理的样式键:

    SystemControlPageBackgroundMediumAltMediumBrush
    

    将这个sn-p添加到一个资源字典中,你对主主题文件的引用之后,它会将所有内容对话框的背景设置为不透明的颜色,以这种方式定义将允许您在深色或浅色模式下支持不同的背景颜色,此示例为每个主题使用相同的颜色,但演示了如何定义不同的颜色:

    <!--  override the Dialog Background  -->
    <ResourceDictionary.ThemeDictionaries>
        <ResourceDictionary x:Key="Default">
            <SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="#99FFFFFF" />
            <SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="#99000000" />
            <StaticResource x:Key="ContentDialogLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
        </ResourceDictionary>
        <ResourceDictionary x:Key="Dark">
            <SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="{ThemeResource SystemColorHighlightColor}" />
            <SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="#99000000" />
            <StaticResource x:Key="ContentDialogLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
        </ResourceDictionary>
    </ResourceDictionary.ThemeDictionaries>
    

    您可以内联执行此操作或将其移动到另一个文件:

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Dictionary1.xaml"/>
    
    
                <ResourceDictionary>
                    <ResourceDictionary.ThemeDictionaries>
                        <ResourceDictionary x:Key="Default">
                            <SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="#99FFFFFF" />
                            <SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="#99000000" />
                            <StaticResource x:Key="ContentDialogLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
                        </ResourceDictionary>
                        <ResourceDictionary x:Key="Dark">
                            <SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="{ThemeResource SystemColorHighlightColor}" />
                            <SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="#99000000" />
                            <StaticResource x:Key="ContentDialogLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
                        </ResourceDictionary>
                    </ResourceDictionary.ThemeDictionaries>
                </ResourceDictionary>
    
    
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    

    【讨论】:

    • 谢谢。我将此添加到项目中,但无法解决问题。对话框仍然覆盖/隐藏它后面的整个页面。此外,您要添加的所有键都不在主题字典中,所以不知道为什么它们会被主题覆盖...
    • @under 能不能截图解释一下,显示前后。我听从了你的指示,这对我有用。
    • 我已经更新了,我没有注意到我已经自定义了我的主题文件
    • 这很有效,谢谢!如果我删除 ContentDialogDimmingThemeBrush 它仍然有效。那有什么作用?
    • 一个问题,它使对话框有些透明。那是哪个楼盘?背景?我不太明白当主题没有更改这些属性时,主题如何设法打破这一点!
    猜你喜欢
    • 2016-07-26
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 2023-03-16
    • 2011-02-01
    • 2020-04-17
    相关资源
    最近更新 更多