C# 是否在UWP上自动安装ContentDialog请求的加载事件?

C# 是否在UWP上自动安装ContentDialog请求的加载事件?,c#,xaml,win-universal-app,windows-10-universal,windows-10-mobile,C#,Xaml,Win Universal App,Windows 10 Universal,Windows 10 Mobile,如何使ContentDialog RequestedTheme加载事件的代码与UWP上的全局主题设置(暗或亮)相同?我使用了这个技巧,但效果不佳: private void ContentDialog_Loading(FrameworkElement sender, object args) { string device = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily; //

如何使ContentDialog RequestedTheme加载事件的代码与UWP上的全局主题设置(暗或亮)相同?我使用了这个技巧,但效果不佳:

private void ContentDialog_Loading(FrameworkElement sender, object args)
        {
           string device = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily; // (Mobile, Team(Surface Hub), Desktop, IoT. Device types.
 if (device == "Windows.Mobile") // If it is a phone
            {


       RequestedTheme = ElementTheme.Default; // Enable automatic theming in mobile.

            }
        }

谢谢。

我认为您在应用后的运行时指定了主题值,例如:

contentDialog.RequestedTheme = ElementTheme.Default;
如中所示,当您将其设置为
Default
时,它将使用元素的
Application.RequestedTheme

因此,我认为在您的代码中的某个地方,当您在移动设备上运行代码时,您已经将
应用程序.RequestedTheme
设置为


要根据用户的设置更改
ContentDialog
的主题或应用程序的主题,默认情况下,您只需删除app.xaml文件中的
RequestedTheme=“Dark”
RequestedTheme=“Light”
,并且不要在代码隐藏中设置任何
应用程序.RequestedTheme
。无需将
元素主题
应用于
内容对话框
,除非您希望更改其主题与设置不同。

我认为您是在应用后的运行时指定主题值,例如:

contentDialog.RequestedTheme = ElementTheme.Default;
如中所示,当您将其设置为
Default
时,它将使用元素的
Application.RequestedTheme

因此,我认为在您的代码中的某个地方,当您在移动设备上运行代码时,您已经将
应用程序.RequestedTheme
设置为


要根据用户的设置更改
ContentDialog
的主题或应用程序的主题,默认情况下,您只需删除app.xaml文件中的
RequestedTheme=“Dark”
RequestedTheme=“Light”
,并且不要在代码隐藏中设置任何
应用程序.RequestedTheme
。无需将
ElementTheme
应用于
ContentDialog
,除非您希望更改其主题与设置不同。

默认情况下,内容对话框将自动适应全局主题,我无法重现您的问题,您在哪里设置了主题?当页面(包含此内容对话框)正在加载时,应触发
ContentDialog\u加载
事件。您是如何创建ContentDialog的?您好。我通过XAML创建了我的内容对话框,而不是代码。我在XAML设计器上将ContentDialog RequestedTheme设置为“Light”,以便在桌面模式下正确运行。是的,你说得对。加载时触发加载事件,但我想执行以下操作:如果设备是Windows Phone,则将ContentDialog的主题设置为Phone默认值(暗或亮)。我的问题是,如果默认设备是Windows Phone,ContentDialog主题每次都是“暗”的。从“设置”更改没有任何效果。如何解决此问题?谢谢。默认情况下,内容对话框将自动适应全局主题,我无法重现您的问题,您在哪里设置了主题?当页面(包含此内容对话框)正在加载时,应触发
ContentDialog\u加载
事件。您是如何创建ContentDialog的?您好。我通过XAML创建了我的内容对话框,而不是代码。我在XAML设计器上将ContentDialog RequestedTheme设置为“Light”,以便在桌面模式下正确运行。是的,你说得对。加载时触发加载事件,但我想执行以下操作:如果设备是Windows Phone,则将ContentDialog的主题设置为Phone默认值(暗或亮)。我的问题是,如果默认设备是Windows Phone,ContentDialog主题每次都是“暗”的。从“设置”更改没有任何效果。如何解决此问题?谢谢