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

Setting the them of a MS control in the control constructor

0 Answers 34 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Patrick asked on 16 Oct 2012, 03:32 PM
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
Tags
General Discussions
Asked by
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or