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

Set Theme

7 Answers 152 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anton Samarin
Top achievements
Rank 1
Anton Samarin asked on 10 Sep 2008, 01:58 PM
How set theme into source code?

this.SetValue(Telerik.Windows.Controls.Theming.ThemeProperty,
new SummerTheme());

this is not work.....

I have class, which succeed to RadGridView.
public class MyGridView : RadGridView
{
      protected override void  OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            CaramelTheme st = new CaramelTheme();
            this.SetValue(Telerik.Windows.Controls.Theming.ThemeProperty, st);
        }
}

Thanks.

7 Answers, 1 is accepted

Sort by
0
Atanas
Telerik team
answered on 10 Sep 2008, 03:43 PM
Hello Anton,

Thank you for pointing out this issue, fixing this bug is in our to do list  for the comming versions of the RadGridView control, your Telerik points have been updated.

Inheriting our RadGridView is not a common scenario and we are wonering if you miss some features requiring inheritance.

I found a workaround for your scenario, all you need to do is to make a static constructor and override DefaultStyleKeyProperty metadata of MyGridView. Here is the code:

static MyGridView() 
    DefaultStyleKeyProperty.OverrideMetadata(typeof(MyGridView),  
        new FrameworkPropertyMetadata(new ThemeResourceKey(typeof(CaramelTheme),  
            typeof(RadGridView)))); 

protected override void OnInitialized(EventArgs e) 
    base.OnInitialized(e); 
    CaramelTheme st = new CaramelTheme(); 
    this.SetValue(Theming.ThemeProperty, st); 
 
    this.InitializeData(); 
 
private void InitializeData() 
    List<Customer> customers = new List<Customer>()  
        { new Customer("James", 30) , 
          new Customer("Richard", 28)}; 
 
    this.ItemsSource = customers; 

I send you a simple project which I hope solves your problems with this issue.

Best wishes,

Atanas
the Telerik team


Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anton Khramov
Top achievements
Rank 1
answered on 11 Sep 2008, 08:56 AM
Thank you, Atanas.
Your workaround works  for Caramel theme, but it doesn't work for SimpleTheme. The following exception was thrown:

{"Cannot create instance of 'MyGridView' defined in assembly 'RunTimeThemeChange, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation.  Error at object 'System.Windows.Controls.Grid' in markup file 'RunTimeThemeChange;component/window1.xaml' Line 8 Position 4."}

Can you provide workaround for this case?

Best regards,
Anton
0
Atanas
Telerik team
answered on 11 Sep 2008, 10:57 AM
Hello Anton,

Our SimpleTheme is in a different assembly(Telerik.Windows.Controls.Simple), so you need to add a reference.
I did not succeed in reproducing you exception, it will be helpful to send more details.

I am attaching a modified copy of the project you already have and want to assure you  the workaround works for all our themes. It is completely neccessary to modify the static constructor of the MyGridView control too:

static MyGridView() 
            DefaultStyleKeyProperty.OverrideMetadata(typeof(MyGridView), 
                new FrameworkPropertyMetadata(new ThemeResourceKey(typeof(SimpleTheme), 
                    typeof(RadGridView)))); 


All the best,
Atanas
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anton Khramov
Top achievements
Rank 1
answered on 11 Sep 2008, 11:21 AM
Hi, Atanas.

Thanks for replay.
Reference to Assembly (Telerik.Windows.Controls.Simple) was added, but the error occured. After I added all Teleriks assemblies it started working. I don't know what reference exactly was needed.

Regards, Anton.

0
Atanas
Telerik team
answered on 11 Sep 2008, 01:28 PM
Hello Anton Khramov,

To use our RadGridView you need references to the following assemblies: Telerik.Windows.Controls, Telerik.Windows.Controls.GridView, Telerik.Windows.Controls.Input, Telerik.Windows.Data.

In your case you also need a reference to Telerik.Windows.Controls.Simple.

The need of Telerik.Windows.Controls.Input  assembly is not quite obvious, and I bet you missed that reference.

Best wishes,
Atanas
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anton Khramov
Top achievements
Rank 1
answered on 12 Sep 2008, 10:23 AM
Hi, Atanas.

Thank you.
Do you have theming for other controls? For examle RadTabControl?

Regard, Anton.
0
Miroslav
Telerik team
answered on 15 Sep 2008, 01:22 PM
Hi Anton,

Currently there are multiple themes only for the GridView and the Carousel. The other controls are not yet part of the common theming mechanism and have only one theme.

By the end of the week we will be able to send you updated assemblies with which you will be able to set the Theming.Theme property for the other controls as well but unfortunately the themes themselves will not be ready before the Q3 release.

Would you like to create custom themes for the controls?

Sincerely yours,
Miroslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Anton Samarin
Top achievements
Rank 1
Answers by
Atanas
Telerik team
Anton Khramov
Top achievements
Rank 1
Miroslav
Telerik team
Share this question
or