Skip to main content

Microsoft Silverlight

Answered Question Working Toolkit Theme SampleRSS Feed

(0)

AntoniDol
AntoniDol

Member

Member

0 points

12 Posts

Working Toolkit Theme Sample

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!

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

NavinKumar.K.S
NavinKum...

Member

Member

295 points

227 Posts

Re: Working Toolkit Theme Sample

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

 

Please Mark "Mark As answer" if this post answers your's question


("-ksnavinkumar@live.com-")

K2P2
K2P2

Participant

Participant

1028 points

337 Posts

Re: Working Toolkit Theme Sample

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;

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>
 

 

 

AntoniDol
AntoniDol

Member

Member

0 points

12 Posts

Re: Working Toolkit Theme Sample

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!

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

bharathkumars87
bharathk...

Member

Member

280 points

51 Posts

Re: Re: Working Toolkit Theme Sample

hai anoni ,

try this

if (UPListIdea.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 (UPListIdea.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 (UPListIdea.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 (UPListIdea.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 (UPListIdea.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);

                        } 

bharath kumar.s
Please "Mark as Answer" if this post answered your question. :)

AntoniDol
AntoniDol

Member

Member

0 points

12 Posts

Answered Question

Re: Working Toolkit Theme Sample

Hi,

 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.

  • Insert an initParam in the <Object> tag in your startup file:

1.<param name="initParams" value="Theme=TheTheme" />

  • Add a Default MergedDictionary in App.xaml:

1.<Application.Resources> 
2.    <ResourceDictionary>
3.        <ResourceDictionary.MergedDictionaries>
4.            <ResourceDictionary Source="Default.xaml"/>
5.        </ResourceDictionary.MergedDictionaries>

  • Declare a private currentTheme variable in App.xaml.cs

1.public partial class App : Application
2.{
3.    private string currentTheme = "Default";
4.    …

  • Set the Default theme, get the initParam, make an URL to the filename and create and RD from that. Then add the RD to the MergedDictionaries:
  • 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. }

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Unanswered Question
    • Answered Question
    • Announcement
    Microsoft Communities