views:

164

answers:

3

Hi I have created two different grid background and radio button style in my

App.xaml.

User can select any style to change the look of the page i.e: Changing the background and style of the radiobutton.

Now When I click on the raduio button the application navigates to another page and the style disappears.

Is there a way to Set the style in application level or I need to store the styleVar as Global Var and check on the second page load and then apply the styles as per the styleVar.

A: 

Place the styles in question in the App.xaml file. The application objects Resources property makes Styles and other resources available across the entire application.

AnthonyWJones
Yes, I am able to set the styles by doing:radioBtn.Style = (Style)(Application.Current.Resources["rdbFolder"]);But I have to repeat the process in all the pages to set the style.Instead I want When I say set the style of the radioBtn on the 1st Page , Itshould be applied to all the radiobuttons in all the pages through out the application.
Subhen
+2  A: 

Just leave off the x:Key part of the Style, inside App.xaml. This is a new feature for Silverlight 4.

Jeff Wilcox
+2  A: 

Yes like Jeff Wilcox said Implicit styling is a new thing in Silverlight 4. So if you want to create a style that is the default for all the controls of that type in the range XAML file or the whole application if placed in App.xaml you would leave out the x:Key attribute.

<Style x:Key="ButtonStyle" TargetType="Button">

To use ButtonStyle you would have to write:

<Button Content="A button" Style="{StaticResource ButtonStyle}" />

Leaving out the x:Key would allow you to use ButtonStyle as default.

<Style TargetType="Button">

<Button Content="A button with style that has no x:Key value" />

Now if you'd need to create a button that doesn't have this default style, you can set the Style property of that button to be x:Null or override by setting a named style to that button.

 <Button Content="Default Silverlight button" Style="{x:Null}"/>

Another new thing with Styles in Silverlight 4 is that you can create new styles that are based on existing ones. Although it wasn't your question I'll give an example:

<Style TargetType="Button" BasedOn="{StaticResource BasedStyle}">

About implicit styling in the docs: http://msdn.microsoft.com/en-us/library/system.windows.style%28VS.95%29.aspx

Implicit Styles

In Silverlight 4, you can set styles implicitly. That is, you can apply a certain style to all elements of a certain type. When a resource is declared without an x:Key value, the x:Key value assumes the value of the TargetType property. If you set the style implicitly, the style is applied only to the types that match the TargetType exactly and not to elements derived from the TargetType value. For example, if you create a style implicitly for all the ToggleButton controls in your application, and your application has ToggleButton and CheckBox controls (CheckBox derives from ToggleButton), the style is applied only to the ToggleButton controls.

BasedOn Styles

Starting with Silverlight 3, it is possible to build a new style based on an existing style. You can do this using the BasedOn property. This reduces the duplication of code and makes it easier to manage resources. Each style supports only one BasedOn style. For more information, see the BasedOn property.

texmex5