Ahmed
Posted
on Nov 13, 2010
(permalink)
In My Silverlight Application which is Based in Telerik Controls ...... I want to Use Telerik Controls Themes but in Dynamic Way ....... So I want To Let User Select His Theme from Combo Box Appear in The Top of The Page and Change Telerik Controls Themes Automatic So can U Give me A simple About How can I Handle It ??
(Note : Beside Telerik Controls I use Also Some Silverlight Controls (Containers) : Like Grid or Stack Panel So
1-Can I Give Telerik Themes to Silverlight Controls ?? If That is Possible so How Can I do That ?
2-If The Pre Question is not Possible So How Can I Handle Silverlight Controls if I Give it Static Colors with Telerik Thems ?
Reply
Answer
Vanya Pavlova
Vanya Pavlova
Posted
on Nov 15, 2010
(permalink)
Hello Ahmed,
I have prepared an example for you that demonstrates how to dynamically change the theme using RadComboBox. The Telerik themes are designed to work with several Microsoft Controls, such as ListBox, TextBox, Button..... If you want to dynamically change the background of a layout container such as Grid, StackPanel, WrapPanel you should do it manually.
Please see the attached example and if you need any further assistance let me know.
Kind regards,
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the
Telerik Public Issue Tracking system and vote to affect the priority of the items
Reply
G
Posted
on Nov 26, 2010
(permalink)
That's a nice example however you have to bind the theme to every control which looks like overkill.
Is there anyway you can do the following (Imagine a theme has been selected from a combobox) in code behind and have it take affect?
Currently you have to restart the xap to have a new theme take affect or is there something I'm missing here? Restarting is an annoyance in a browser and impossible OOB from what I've been able to find.
Thanks.
Reply
Vanya Pavlova
Vanya Pavlova
Posted
on Nov 29, 2010
(permalink)
Hi GF,
You can use code behind within RadComboBox's SelectionChanged event to achieve your goal, but each time you dynamically change the ApplicationTheme the view will be recreated. Having in mind this fact the preferable approach is to apply the theme using Style Manager to each control as it was demonstrated in my previous example.
Greetings,
Vanya Pavlova
the Telerik team
Browse the
videos here>> to help you get started with RadControls for Silverlight
Reply
Posted
on Feb 23, 2011
(permalink)
I've encountered the same task - switching theme at runtime. I finally came up with this solution:
(just insert in App.xaml.cs)
public Theme ApplicationTheme
{
get { return StyleManager.ApplicationTheme; }
set
{
StyleManager.ApplicationTheme = value;
Binding binding = new Binding("ApplicationTheme") { Source = this, Mode = BindingMode.TwoWay };
foreach (var element in (RootVisual as FrameworkElement).AllChildren<FrameworkElement>().ToList())
element.SetBinding(Telerik.Windows.Controls.StyleManager.ThemeProperty, binding);
}
}
Extension, I used:
public static IEnumerable<T> AllChildren<T>(this FrameworkElement ele, Func<T, bool> whereFunc = null) where T : FrameworkElement
{
var c = VisualTreeHelper.GetChildrenCount(ele);
for (var i = 0; i < c; i++)
{
var child = VisualTreeHelper.GetChild(ele, i);
if (child is T)
{
var childOfTypeT = child as T;
if (whereFunc != null && !whereFunc(childOfTypeT))
continue;
yield return childOfTypeT;
foreach (var nextchild in childOfTypeT.AllChildren<T>(whereFunc))
yield return nextchild;
}
}
}
Reply
Joel Palmer
Posted
on Feb 6, 2012
(permalink)
Sven, I'd like to use your approach but I can't get it working. Is your example using Silverlight 5; Visual Studio 2010?
I get errors on the [RootVisual as FrameworkElement).AllChildren] part of your code because AllChildren isn't an option on that item.
Maybe I don't have your references. Is FrameworkElement from System.Windows?
Thanks, Joel
Reply