【问题标题】:RadDataGrid not updating theme in runtimeRadDataGrid 不在运行时更新主题
【发布时间】:2018-03-08 16:09:02
【问题描述】:

我正在使用“Telerik UI for Universal Windows Platform”的免费/开源版本。

我的问题是我的 UWP 应用支持深色/浅色主题,并在运行时响应 RequestedTheme 的更改(使用 RootFrame.RequestedTheme)。但 RadDataGrid 不会回应它,即使我相信我已经按照找到的文档 here。 RadDataGrid 与它开始时的主题一起工作,但不会反映在运行时应用的更改。

我尝试使用带有设置、Telerik DataataGrid 和 Telerik Graph 的 Windows Template Studio 创建一个全新的应用程序。 Graph 页面在运行时响应 Settings.Theme 更改,但网格页面没有。

所以我的问题是。它不适用于 DataGrid 吗?这是一个错误吗?还是我必须以其他方式处理它?

【问题讨论】:

  • 我遇到了类似的问题,当更改应用程序主题颜色时,它不会影响我想随着应用程序系统强调颜色更改而更改的 RadDatagrid 强调颜色蓝色。如果您对此有任何解决方案,请提供帮助。谢谢。

标签: uwp telerik


【解决方案1】:

一种可行的方法是将ResourceDictionary 放在Page.Resources 中。

Page.xaml,

<Page
    ...
    xmlns:telerikGrid="using:Telerik.UI.Xaml.Controls.Grid"
    xmlns:telerik="using:Telerik.UI.Xaml.Controls"
    RequestedTheme="Dark"
    mc:Ignorable="d">
    <Page.Resources>
        <ResourceDictionary>
            <telerik:UserThemeResources x:Key="themeResourceInitializer"/>
            <ResourceDictionary.ThemeDictionaries>
                <ResourceDictionary x:Key="Default">
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary Source="ms-appx:///Telerik.UI.Xaml.Grid.UWP/Themes/ThemeResourcesDark.xaml"/>
                        <ResourceDictionary Source="{CustomResource DarkResourcesPath}"/>
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
                <ResourceDictionary x:Key="Light">
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary Source="ms-appx:///Telerik.UI.Xaml.Grid.UWP/Themes/ThemeResourcesLight.xaml"/>
                        <ResourceDictionary Source="{CustomResource LightResourcesPath}"/>
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
            </ResourceDictionary.ThemeDictionaries>
        </ResourceDictionary>
    </Page.Resources>

    <StackPanel>
        <telerikGrid:RadDataGrid x:Name="DataGrid" Height="600"/>
        <Button Content="change theme" Background="Orange" Click="Button_Click"/>
    </StackPanel>
</Page>

Page.xaml.cs,

private void Button_Click(object sender, RoutedEventArgs e)
{
    if (this.RequestedTheme == ElementTheme.Light)
    {
        this.RequestedTheme = ElementTheme.Dark;
    }
    else
    {
        this.RequestedTheme = ElementTheme.Light;
    }
}

【讨论】:

  • 该解决方案似乎有效,但我不喜欢将它添加到每个页面。因此,我最终像在照片应用中一样进行主题切换,其中主题仅在应用启动时进行一次。
猜你喜欢
  • 2021-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多