Hello,
I'm working on an app where users may switch a theme from within the supported telerik themes (metro, vista, office_black, etc...).
The theme is kept as a preference at user level and restored at login.
Now in order to remain consistent with the current theme in use, I want to avoid using any predifines fixed brushes and use the theme palette instead. So I'm facing 2 problems:
1) Retreiving the current application theme in use.
As I load themes using the documented method:
In order to retreive the current theme I haven't found anything prettier than checking the current merged dictionnaries and extracting the theme name from there:
I can do that or just keep track of the current them when it's loaded.
But isn't there any more obvious way of accessing the current theme in use?
2) Using the current Theme pallete
Once I get the theme name, I could decide of an approriate color for the theme in use...
But, for a metro style i have found the following is possible:
I can alter my interface using the colorpalette maincolor, accentcolor, strongColor, etc... and remain consistent with the theme.
How do I get a color pallete's ref of the other themes (Expression_Dark, Vista, Summer, etc...) and achieve the same result.
Many thanks.
I'm working on an app where users may switch a theme from within the supported telerik themes (metro, vista, office_black, etc...).
The theme is kept as a preference at user level and restored at login.
Now in order to remain consistent with the current theme in use, I want to avoid using any predifines fixed brushes and use the theme palette instead. So I'm facing 2 problems:
1) Retreiving the current application theme in use.
As I load themes using the documented method:
Application.Current.Resources.MergedDictionaries.Clear()
Dim
res1
As
ResourceDictionary =
New
ResourceDictionary()
res1.Source =
New
Uri(
"/Telerik.Windows.Themes.Expression_Dark;component/Themes/System.Windows.xaml"
, UriKind.RelativeOrAbsolute)
Dim
res2
As
ResourceDictionary =
New
ResourceDictionary()
res2.Source =
New
Uri(
"/Telerik.Windows.Themes.Expression_Dark;component/Themes/Telerik.Windows.Controls.xaml"
, UriKind.RelativeOrAbsolute)
Dim
res3
As
ResourceDictionary =
New
ResourceDictionary()
res3.Source =
New
Uri(
"/Telerik.Windows.Themes.Expression_Dark;component/Themes/Telerik.Windows.Controls.Input.xaml"
, UriKind.RelativeOrAbsolute)
...
Application.Current.Resources.MergedDictionaries.Add(res1)
Application.Current.Resources.MergedDictionaries.Add(res2)
Application.Current.Resources.MergedDictionaries.Add(res3)
In order to retreive the current theme I haven't found anything prettier than checking the current merged dictionnaries and extracting the theme name from there:
Dim
str
As
String
= My.Application.Current.Resources.MergedDictionaries(1).Source.OriginalString
str = Strings.Mid(str, 25, str.Length)
str = Left(str, str.IndexOf(
";"
))
'Returns the Theme's name in use
I can do that or just keep track of the current them when it's loaded.
But isn't there any more obvious way of accessing the current theme in use?
2) Using the current Theme pallete
Once I get the theme name, I could decide of an approriate color for the theme in use...
But, for a metro style i have found the following is possible:
Dim
colorPalette = MetroColors.PaletteInstance
Dim
converter
As
New
System.Windows.Media.BrushConverter
Me
.gridStatus.Background =
DirectCast
(converter.ConvertFromString(colorPalette.AccentColor.ToString), Brush)
I can alter my interface using the colorpalette maincolor, accentcolor, strongColor, etc... and remain consistent with the theme.
How do I get a color pallete's ref of the other themes (Expression_Dark, Vista, Summer, etc...) and achieve the same result.
Many thanks.