【问题标题】:UWP Change theme in pop ups MVVM Light弹出窗口中的 UWP 更改主题 MVVM Light
【发布时间】:2022-01-24 13:48:44
【问题描述】:
public static async Task SetRequestedThemeAsync()
        {
            foreach (var view in CoreApplication.Views)
            {
                await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    if (Window.Current.Content is FrameworkElement frameworkElement)
                    {
                        frameworkElement.RequestedTheme = Theme;
                    }
                });
            }
        }

这是我的代码,可以正确更改我的应用程序中的视图主题,但现在我有一些 ContentDialogs 并且它们不会更改主题。 所以在这种情况下,我想问两个问题:

  1. 我在静态完整属性中满足我的弹出窗口。这是一个好的决定还是每次都创建一个新的弹出对象会更好?
  2. 如果静态属性是一个不错的决定,如何更改其中的主题?

【问题讨论】:

    标签: c# uwp mvvm-light


    【解决方案1】:

    ContentDialogs,它们不会改变主题。

    看起来已知问题here。请随时为这份报告投票。目前有一种解决方法可以在显示弹出窗口时设置对话框的主题,如下所示。

    private async void Button_Click(object sender, Windows.UI.Xaml.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 = "Test Theme";
        dialog.RequestedTheme = (Window.Current.Content as FrameworkElement).RequestedTheme;
    
    
        var result = await dialog.ShowAsync();
    
    }
    

    【讨论】:

    • 但我的设置也是 ContentDialog。我需要动态改变他的主题和背景。我也有这个问题。
    • 另一种是自定义ContentDialog的样式,用不同的主题资源设置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 2015-03-03
    • 2016-05-23
    • 1970-01-01
    相关资源
    最近更新 更多