Paw
Paw

Reputation: 43

RadDataGrid not updating theme in runtime

I am using the free/opensource version of "Telerik UI for Universal Windows Platform".

My issues is that my UWP app supports dark/light themes and responds in runtime to changes to the RequestedTheme (using RootFrame.RequestedTheme). But RadDataGrid will not respond to it, even though I believe I have followed the documentation found here. The RadDataGrid works with the theme it starts with, but will not reflect changes applied in runtime.

I have tried to create a completely new app using Windows Template Studio with implementation of Settings, Telerik DDataataGrid and a Telerik Graph. The Graph page responds in runtime to a Settings.Theme change but the grid page does not.

So my question is. Does it not work for DataGrid? Is it a bug? Or do I have to handle it in another way?

Upvotes: 1

Views: 139

Answers (1)

Breeze Liu - MSFT
Breeze Liu - MSFT

Reputation: 3808

A workable way is to put the ResourceDictionary in the 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;
    }
}

Upvotes: 1

Related Questions