NoXaml Custom Syle RadGridView

8 posts, 0 answers
  1. luc
    luc avatar
    24 posts
    Member since:
    Aug 2011

    Posted 21 Aug 2014 Link to this post

    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
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Aug 2014 Link to this post

    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.
     
  3. luc
    luc avatar
    24 posts
    Member since:
    Aug 2011

    Posted 22 Aug 2014 in reply to Dimitrina Link to this post

    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
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 26 Aug 2014 Link to this post

    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.
     
  5. luc
    luc avatar
    24 posts
    Member since:
    Aug 2011

    Posted 30 Aug 2014 in reply to Dimitrina Link to this post

    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
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 01 Sep 2014 Link to this post

    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.
     
  7. luc
    luc avatar
    24 posts
    Member since:
    Aug 2011

    Posted 01 Sep 2014 in reply to Dimitrina Link to this post

    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
  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 02 Sep 2014 Link to this post

    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.
     
Back to Top