This is a migrated thread and some comments may be shown as answers.

NoXaml Custom Syle RadGridView

7 Answers 139 Views
GridView
This is a migrated thread and some comments may be shown as answers.
luc
Top achievements
Rank 1
luc asked on 21 Aug 2014, 07:55 PM
Hi,

I try to follow the thread about CustomStyle (http://www.telerik.com/help/wpf/styling-apperance-custom-styles-themes-runtime.html) by replacing the RadButton by a RadGridView.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="telerik:RadGridView" BasedOn="{StaticResource RadGridViewStyle}">
        <Setter Property="Background" Value="Red"/>
    </Style>
</ResourceDictionary>

When I click on Button to switch the theme, an exception is raised ('System.Windows.Markup.XamlParseException') because it's not able to resolve the RadGridViewStyle. It seems that it can not resolve staticresource presents in another files (app.xaml), i don't understand why it's work with RadButton and not RadGridView.

Thanks for feedback.
Regards

7 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 22 Aug 2014, 02:14 PM
Hi,

Have you merged the respective ResourceDictionary for RadGridView?
<ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.GridView.xaml"/>

You can also check our online documentation on Implicit Styles for a further reference on how to apply styling.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
luc
Top achievements
Rank 1
answered on 22 Aug 2014, 02:29 PM
Hi,

You can found a sample project here 
The goal is to follow the post about custom style and not to reference telerik theme in custom xaml file directly. Like it's work for RadButtonStyle, I suppose it can be work for others controls.
Thanks.
Regards
0
Dimitrina
Telerik team
answered on 26 Aug 2014, 08:03 AM
Hi,

The reason why RadGridView does not respect the changed Theme's settings is that you have not merged the respected resource dictionary.
You should do similarly to how it is done for the Telerik.Windows.Controls.xaml dictionary (the one needed for displaying RadButton).
For example:
private void Office_Black_Click(object sender, RoutedEventArgs e)
{
    Application.Current.Resources.MergedDictionaries.Clear();
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
    {
        Source = new Uri("/Telerik.Windows.Themes.Office_Black;component/Themes/System.Windows.xaml", UriKind.RelativeOrAbsolute)
    });
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
    {
        Source = new Uri("/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml", UriKind.RelativeOrAbsolute)
    });
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
    {
        Source = new Uri("/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.GridView.xaml", UriKind.RelativeOrAbsolute)
    });
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
    {
        Source = new Uri("/CustomStyles;component/Themes/Custom.xaml", UriKind.RelativeOrAbsolute)
    });
}

I updated the sample project and you can find it attached.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
luc
Top achievements
Rank 1
answered on 30 Aug 2014, 04:38 PM
Hi,

Indeed I miss the griedview.xaml, thank you.

Instead of enumerate each xaml in code, I create a Resource Dictionary page with content :
<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/System.Windows.xaml"/>
    <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml"/>
    <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.GridView.xaml"/>
    <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.Input.xaml"/>
    <ResourceDictionary Source="/CustomStyles;component/Themes/Custom.xaml"/>
</ResourceDictionary.MergedDictionaries>

and in the code I try to load only the new resource
Application.Current.Resources.MergedDictionaries.Clear();            Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()            
{                Source =
new Uri("/Dictionary1.xaml", UriKind.RelativeOrAbsolute)            });

This way raise again an exception when trying to resolve RadGridViewStyle. Do you see why ?
Thank
Regards
0
Dimitrina
Telerik team
answered on 01 Sep 2014, 07:00 AM
Hi,

I notice that you first clear all the MergedDictionaries. Is it possible that this is the reason for the crash?
If not, may I ask you to update the demo project and send it back to me? That way I will be able to advise further.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
luc
Top achievements
Rank 1
answered on 01 Sep 2014, 08:06 AM
Hi,

You can found an updated project here
In fact it's more related at the way wpf search in dictionary, if first telerik dictionaries are loaded and after custom it's work, not if all dictionaries are in same xaml file.
Regards
Luc
0
Dimitrina
Telerik team
answered on 02 Sep 2014, 12:43 PM
Hi Luc,

I am indeed able to reproduce the issue. The exception should be thrown due to some problem with loading of the ResourceDictionaries one after another in the correct order during the first layout update.

I can suggest you loading the dictionaries separately, or not clearing the already loaded ones:
private void AllInOne_Click(object sender, RoutedEventArgs e)
{
    //Application.Current.Resources.MergedDictionaries.Clear();
    
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
    {
        Source = new Uri("/CustomStyles;component/AllInOne.xaml", UriKind.RelativeOrAbsolute)
    });
}

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
luc
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
luc
Top achievements
Rank 1
Share this question
or