SpriteHand
Module Border
  Silverlight 4 Beta: Implicit Styles
Module Border
Location: BlogsAndy's Blog    
Posted by: host 11/18/2009 5:24 PM

The ability to create Implicit Styles has been a sorely missed feature in Silverlight… until Silverlight 4! The concept of an implicit style is very simple – you define how you want ALL instances of a control to look in one place (you can then override those styles if you need to).

Setting an implicit style in XAML

Let’s say we want all of our TextBox controls in our application to have White text on a Red background. We can step into our App.xaml and add the following XAML:

    <Application.Resources>
              <Style TargetType="TextBox">
                     <Setter Property="Background" Value="#FFFF0000"/>
                     <Setter Property="Foreground" Value="#FFFFFFFF"/>
              </Style>
    </Application.Resources>

The key here is that we did NOT specify an x:Key value on the TextBox – only a TargetType. After this change, if we add a couple of TextBox controls to a UserControl, we’ll see the style take effect:

<StackPanel Width="100">
       <TextBox Text="TextBox 1" />
       <TextBox Text="TextBox 2" />
</StackPanel>


Of course, we can override a property that is styled if we wish – for example maybe we want to change the foreground colors of the TextBoxes to a color other than White:

<StackPanel Width="100">
       <TextBox Text="TextBox 1" Foreground="Blue" />
       <TextBox Text="TextBox 2" Foreground="Green" />
</StackPanel>

Creating Implicit Styles in Blend

To create an Implicit Style in Blend, right-click an element and select Edit Template/Edit a Copy or Edit Template/Create Empty.

… then select the “Apply to all” radio button option in the Create Style Resource dialog:

Some Limitations

Currently, Silverlight 4 does not support BasedOn styling for Implicit Styles. This is possible in WPF and allows for the “tweaking” of a style at a local scope. For example, you may define an Implicit style for a TextBox at the application level, but then want to tweak just a couple of properties of the style in a local scope (maybe a UserControl or Container).

Permalink |  Trackback

Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Subscribe
Module Border
RSS   Twitter
Module Border Module Border
Module Border
  Diversions
Module Border

TALKING RAGDOLL
This Windows Phone 7 App was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine. It gets interesting when you import your friends photos and have your way with them!

MORE INFO



DROPPYPOP
This Windows Phone 7 game was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine.
DEMO

MORE INFO



BOSS LAUNCH
This physics game won first place in the Server Quest Contest. Created using Silverlight 2, the Physics Helper Library,  and the Farseer Physics Engine.
PLAY IT

MORE INFO



DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight 2.
PLAY IT

INFO AND CODE



PHYSICS HELPER DEMOS
These demos were created for the Physics Helper Library, which makes it easy to create physics games and simulations using Expression Blend, Silverlight, and the Farseer Physics Engine.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game took first place in the TeamZoneSports Silverlight Contest. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight 2.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2013 andy.beaulieu.com - Login