Skip to main content
Home Forums Silverlight Design Designing with Silverlight Working Toolkit Theme Sample
5 replies. Latest Post by AntoniDol on November 3, 2009.
(0)
AntoniDol
Member
0 points
12 Posts
10-22-2009 6:28 AM |
Hi,
I can't get the Toolkit Theming to work with the October Release.Do you know a working example that just applies a theme OneTime?
Thx in Advance!
NavinKum...
295 points
227 Posts
10-22-2009 6:53 AM |
This is the Method to apply themes
i hope It Will Help u
FrmName.Loaded += (obj, e) => System.Diagnostics.Debug.WriteLine("Loaded");
LinearGradientBrush brush = new LinearGradientBrush(); GradientStop colorStop1 = new GradientStop(); colorStop1.Color = startColor; GradientStop colorStop2 = new GradientStop(); colorStop2.Color = endColor; colorStop2.Offset = 1; brush.StartPoint = new System.Windows.Point(0.5, 1); brush.EndPoint = new System.Windows.Point(0.5, 0); brush.GradientStops = new GradientStopCollection { colorStop1, colorStop2 }; LayoutRoot.Background = brush; Uri uri = new Uri(XamlPath, UriKind.Relative); ImplicitStyleManager.SetResourceDictionaryUri(FrmName, uri); ImplicitStyleManager.SetApplyMode(FrmName, ImplicitStylesApplyMode.OneTime); ImplicitStyleManager.Apply(FrmName);
This is the code which works fine for me but it has many lines that i cant send if u send me the mail id i will send as attach ment
K2P2
Participant
1028 points
337 Posts
10-22-2009 7:35 AM |
Have you had theming working before? Or is it just the october release? I haven't looked at / downloaded october. 1) Code behind:ExpressionDarkTheme expressionDarkTheme = new ExpressionDarkTheme (); expressionDarkTheme .Content = scrollViewer;
Have you had theming working before? Or is it just the october release? I haven't looked at / downloaded october.
scrollViewer and its content will be themed.
LayoutUpdated += new EventHandler ( MainPage_LayoutUpdated ); private void MainPage_LayoutUpdated () { // Allow the theme to take effect. ImplicitStyleManager .SetApplyMode ( this, ImplicitStylesApplyMode.Auto ); ImplicitStyleManager .Apply ( this ); }
2) Xaml:
<UserControl x:Class="Tester.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:rpt="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.RainierPurple" Width="800" Height="600"> <rpt:RainierPurpleTheme > <Canvas x:Name="LayoutRoot" Background="White"> </Canvas> </rpt:RainierPurpleTheme> </UserControl>
10-22-2009 7:48 AM |
To Clarify:
I want a Silverlight application to have four different themes.The theme need not be changed at runtime, in fact it shouldn't be.The theme could be loaded using StartupParameters or a configuration file.Which should be relatively easy to do for an application administrator.I do not want to use an existing theme, but create four new ones.I do not want to recreate a visual tree from scratch, just apply one of four themes one time.
I can't get the Toolkit Theming to work. I have the October release installed.I did never have a working theme, so I don't know if that's related...
thx again!
bharathk...
280 points
51 Posts
11-03-2009 3:35 AM |
hai anoni ,
try this
if (UPList.Value == 1) { ap.Themes = "1"; Uri uri = new Uri(@"MenuCreation;component/Themes/System.Windows.Controls.Theming.ShinyBlue.xaml", UriKind.Relative); ImplicitStyleManager.SetResourceDictionaryUri(LayoutRoot, uri); ImplicitStyleManager.SetApplyMode(LayoutRoot, ImplicitStylesApplyMode.Auto); ImplicitStyleManager.Apply(LayoutRoot); } else if (UPList.Value == 2) { ap.Themes = "2"; Uri uri = new Uri(@"MenuCreation;component/Themes/System.Windows.Controls.Theming.ShinyRed.xaml", UriKind.Relative); ImplicitStyleManager.SetResourceDictionaryUri(LayoutRoot, uri); ImplicitStyleManager.SetApplyMode(LayoutRoot, ImplicitStylesApplyMode.Auto); ImplicitStyleManager.Apply(LayoutRoot); } else if (UPList.Value == 3) { ap.Themes = "3"; Uri uri = new Uri(@"MenuCreation;component/Themes/System.Windows.Controls.Theming.TwilightBlue.xaml", UriKind.Relative); ImplicitStyleManager.SetResourceDictionaryUri(LayoutRoot, uri); ImplicitStyleManager.SetApplyMode(LayoutRoot, ImplicitStylesApplyMode.Auto); ImplicitStyleManager.Apply(LayoutRoot); } else if (UPList.Value == 4) { ap.Themes = "4"; Uri uri = new Uri(@"MenuCreation;component/Themes/System.Windows.Controls.Theming.RainierOrange.xaml", UriKind.Relative); ImplicitStyleManager.SetResourceDictionaryUri(LayoutRoot, uri); ImplicitStyleManager.SetApplyMode(LayoutRoot, ImplicitStylesApplyMode.Auto); ImplicitStyleManager.Apply(LayoutRoot); } else if (UPList.Value == 5) { Uri uri = new Uri(@"MenuCreation;component/Themes/System.Windows.Controls.Theming.RainierPurple.xaml", UriKind.Relative); ImplicitStyleManager.SetResourceDictionaryUri(LayoutRoot, uri); ImplicitStyleManager.SetApplyMode(LayoutRoot, ImplicitStylesApplyMode.Auto); ImplicitStyleManager.Apply(LayoutRoot); }
11-03-2009 3:59 AM |
Actually I got a solution working, even though it is not Blendable (yet):
Create ResourceDictionaries for the Default Theme and for one or more other Themes that you want to load in the root of your Silverlight project. Use x:Keys for Styles and Resources and keep them the same between RD’s. Set the Build Action for these RD’s to CONTENT in Visual Studio or by editing your .CSPROJ file by hand.
1.<param name="initParams" value="Theme=TheTheme" />
1.<Application.Resources> 2. <ResourceDictionary> 3. <ResourceDictionary.MergedDictionaries> 4. <ResourceDictionary Source="Default.xaml"/> 5. </ResourceDictionary.MergedDictionaries>
1.public partial class App : Application 2.{ 3. private string currentTheme = "Default"; 4. …
01. private void Application_Startup(object sender, StartupEventArgs e) 02. { 03. 04. //set the current theme to the currentTheme variable 05. string currentThemeName = string.Format("{0}.xaml", currentTheme); 06. 07. //get the theme name from the initParam 08. string themeParameter = e.InitParams["Theme"]; 09. 10. if (!string.IsNullOrEmpty(currentThemeString)) 11. { 12. //set the current theme to the theme parameter and create filename 13. currentThemeName = string.Format("{0}.xaml", themeParameter); 14. 15. //create an URL from the currentThemeName 16. Uri themeUrl = new Uri(currentThemeName, UriKind.RelativeOrAbsolute); 17. 18. try 19. { 20. //create a RD and set the source to the URL 21. ResourceDictionary themeDictionary = new ResourceDictionary 22. { 23. Source = themeUrl 24. }; 25. 26. //Add the RD as a MergedDictionary 27. Application.Current.Resources.MergedDictionaries.Add(themeDictionary); 28. } 29. catch (Exception ex) 30. { 31. //communicate theme doesn’t exist 32. throw; 33. } 34. } 35. 36. this.RootVisual = new MainPage(); 37. 38. }