Setting the them of a MS control in the control constructor

1 posts, 0 answers
  1. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 16 Oct 2012 Link to this post

    Hello,
    create a new Telerik WPF application and

    Create a class MyCheckBoxBox.cs, with:
    using System;
    using System.Windows.Controls;
    using Telerik.Windows.Controls;
     
    namespace RadControlsWpfApp2
    {
      class MyCheckBox : CheckBox
      {
        public MyCheckBox() {
          StyleManager.SetTheme(this, StyleManager.ApplicationTheme);
        }
      }
    }

    Replace MainWindow.cs with:
    using System;
    using System.Windows;
    using Telerik.Windows.Controls;
     
    namespace RadControlsWpfApp2
    {
      /// <summary>
      /// Interaction logic for MainWindow.xaml
      /// </summary>
      public partial class MainWindow : Window
      {
        public MainWindow()
        {
          StyleManager.ApplicationTheme = new SummerTheme();
          InitializeComponent();
          StyleManager.SetTheme(CheckBox3, StyleManager.ApplicationTheme);
        }
      }
    }

    Replace MainWindow.xaml.cs with:
    <Window
      x:Class="RadControlsWpfApp2.MainWindow"
      xmlns:my="clr-namespace:RadControlsWpfApp2"
      Title="MainWindow" Height="350" Width="525">
      <Grid HorizontalAlignment="Center"
            Margin="5"
            VerticalAlignment="Center">
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
         
        <CheckBox Content="With theme set in XAML"
                  Margin="5"
                  telerik:StyleManager.Theme="Summer" />
     
        <my:MyCheckBox Content="With theme set in code-behind (control)"
                       Margin="5"
                       Grid.Row="1" />
     
        <CheckBox Name="CheckBox3"
                  Content="With theme set in code-behind (main page)"
                  Margin="5"
                  Grid.Row="2" />
     
      </Grid>
    </Window>

    Now run the application.

    The second check box is not displayed in the window!
    The same code (setting the theme in the control, just after the call to the inherited constructor) works well in Silverlight, but now in WPF.

    Do you have a solution to make it work correctly in WPF, while having the same code for Silverlight?

    Patrick
Back to Top