Change theme(style??) programmatically

7 posts, 1 answers
  1. Aeroth
    Aeroth avatar
    17 posts
    Member since:
    Oct 2010

    Posted 08 Aug 2011 Link to this post

    Hi Telerik Team,
    How can I change RadWinow theme (style??) programmatically?
    I've created a new class(not xaml file) that inherits from RadWindow and I'd like to change foreground and background of the Header, and the style of Minimize, Maximize, Close (X) buttons when my custom window instantiated.
    As your demo example, the Header foreground is white and background is blue.

    Where can I get all default themes list? 

    Please help me out , thanks!

    Regards,
    Aeroth Lin
  2. Dani
    Admin
    Dani avatar
    848 posts

    Posted 08 Aug 2011 Link to this post

    Hi Aeroth,

    RadControls ship with nine ready-to-use themes. You can use them to customize the appearance of the RadWindow control. The one you are referring to and the one that is used thoughout our online demos is the Metro theme. Other themes include: Office Black, Office Blue, Office SIlver, Vista, Summer, Windows7, Transparent, Expression Dark. You can check all of them in the theming example of RadWidnow.

    So to force your instance of RadWindow to have the look and feel of any of the themes, you should apply a theme to it. In XAML:
    <telerik:RadWindow telerik:StyleManager.Theme="Metro" />

    In code-behind:
    StyleManager.SetTheme(myWindow, new MetroTheme());

    Or set an application theme:
    StyleManager.ApplicationTheme = new MetroTheme();

    If you choose to have one of the themes , but wish to apply additional changes to the look & feel, you should make customizations upon the XAML for that particular theme.

    I hope this helps.

    Kind regards,
    Dani
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
  3. DevCraft banner
  4. Aeroth
    Aeroth avatar
    17 posts
    Member since:
    Oct 2010

    Posted 08 Aug 2011 Link to this post

    Hi Dani,
    Thanks for the reply. I added a reference to Telerik.Windows.Themes.Office_Blue.dll and set the theme to Office_BlueTheme but it does not work. Did I miss anything?
    StyleManager.SetTheme(this, new Office_BlueTheme());
    Regards,
    Aeroth Lin
  5. Answer
    Dani
    Admin
    Dani avatar
    848 posts

    Posted 09 Aug 2011 Link to this post

    Hello Aeroth,

    You have to make sure that you add this line before InitializeComponent(). Attached is a working sample. It contains a RadWindow both as a separate UserControl and as an element inside the MainPage UserControl.

    I hope this helps.

    Kind regards,
    Dani
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
  6. Aeroth
    Aeroth avatar
    17 posts
    Member since:
    Oct 2010

    Posted 09 Aug 2011 Link to this post

    Hi Dani,

    The attached sample works. Unfortunately mine does not =.=, I don't know where's going wrong.
    Please check this for me:

    MyRadWindow.xaml
    <navigation:RadWindow x:Class="MySilverlight.Controls.MyRadWindow"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               mc:Ignorable="d"
               xmlns:navigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
               d:DesignWidth="640" d:DesignHeight="480">
        <Grid x:Name="LayoutRoot">
     
        </Grid>
    </navigation:RadWindow>

    MyRadWindow.xaml.cs
    public partial class MyRadWindow : RadWindow
        {
            #region Constructor
            public MyRadWindow()
            {
                StyleManager.SetTheme(this, new Office_BlueTheme());
                InitializeComponent();
                 
                Grid grid = new Grid();
                grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
                grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(10, GridUnitType.Star) });
                TextBox content = new TextBox()
                {
                    IsReadOnly = true,
                    Background = new SolidColorBrush(Colors.White),
                    TextWrapping = TextWrapping.Wrap,
                    FontSize = 13F
                };
                Grid.SetRow(content, 0);
                Grid.SetColumn(content, 0);
                grid.Children.Add(content);
                base.Content = grid;
                base.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterScreen;
                base.Width = 500;
                base.Height = 100;
            }
            #endregion
        }


    Regards,
    Aeroth Lin
  7. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 11 Aug 2011 Link to this post

    Hi Aeroth,

    We tested your code and it worked perfectly fine on our side. I have also attached working sample project that is using your code.

    If you have any further problems could you please send us back a sample not working project?

    Kind regards,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  8. Aeroth
    Aeroth avatar
    17 posts
    Member since:
    Oct 2010

    Posted 11 Aug 2011 Link to this post

    Hi Ivo,

    It works perfectly now, I frogot to add Assembly reference to my addin file.
    <Assembly name="Telerik.Windows.Themes.Office_Blue.dll" checksum="f00" />
    Thanks for the great help.

    Regards,
    Aeroth Lin
Back to Top
DevCraft banner