Dotneteers.net
All for .net, .net for all!

Extract styles in Expression Blend

You may have found yourself in a situation when you want to convert an implicit style in XAML into a resource. Until today, I did it with creating the new style, and adding the setters manually. But I thought “There must be some way in Expression Blend to do this better”. I couldn’t find anything on the net, so I started to look for the solution myself. And yeah, I found it… Here is how it is done:

Suppose, you have a TextBox that has a lot of settings on it:

image

 

<TextBlock Margin="50,96,0,0" VerticalAlignment="Top" Text="TextBlock" TextWrapping="Wrap" FontSize="96" FontFamily="Comic Sans MS" FontWeight="Bold" HorizontalAlignment="Left" Width="248">
    <TextBlock.Projection>
        <PlaneProjection RotationY="-57"/>
    </TextBlock.Projection>
    <TextBlock.Effect>
        <DropShadowEffect BlurRadius="9"/>
    </TextBlock.Effect>
    <TextBlock.Foreground>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="Black" Offset="0"/>
            <GradientStop Color="#FFE82E2E" Offset="1"/>
        </LinearGradientBrush>
    </TextBlock.Foreground>
</TextBlock>

Now, you want to take the font settings, the drop shadow and the Black-Blue foreground gradient and reuse it on another TextBlock. Here is where extracting the style comes handy.

First, select the TextBlock, and choose Object / Style / Create Empty from the menu. There is NO right click option for this command! Then choose a name for your style resource.

image

Now, we are in Resource editing mode:

image

On the Properties tab, you can see all our settings.

image

But the Property Peg is empty (gray). What happens if we click on it?

image

Now, if we click on “Convert To Local Value”, the Peg turns white, and the Foreground gradient will be moved to the style!

 

image

You can see that the TextBlock does not contain the Foreground property anymore, but the TextBlockStyle1 style does. We can go and “Convert to Local Value” for all properties we want in the style. Even the drop shadow and the Perspective transform can be extracted this way.

Here is the end result:

image

Nice and clean XAML for the TextBlock, and the style is ready to be reused. Great!


Posted Jan 19 2010, 04:34 PM by vbandi

Comments

Raghuraman wrote re: Extract styles in Expression Blend
on Tue, Jan 19 2010 17:54

Great shortcut. Thanks for sharing

raghuraman

Adam Kinney wrote re: Extract styles in Expression Blend
on Tue, Jan 19 2010 18:23

Great post András! That's a wonderful feature to point out.

uberVU - social comments wrote Social comments and analytics for this post
on Tue, Jan 19 2010 18:31

This post was mentioned on Twitter by vbandi: New Blog Post: Extract Styles in Expression Blend. http://is.gd/6Bbd9

Twitted by corcav wrote Twitted by corcav
on Tue, Jan 19 2010 22:11

Pingback from  Twitted by corcav

Cigdem wrote re: Extract styles in Expression Blend
on Tue, Jan 19 2010 23:38

That's a neat+handy feature; thanks for sharing!

shemesh wrote re: Extract styles in Expression Blend
on Wed, Jan 20 2010 9:39

this is not  "feature" this is a workaround.

vbandi wrote re: Extract styles in Expression Blend
on Wed, Jan 20 2010 9:52

Shemesh, how is this not a feature?

Dew Drop – January 20, 2010 | Alvin Ashcraft's Morning Dew wrote Dew Drop &#8211; January 20, 2010 | Alvin Ashcraft&#039;s Morning Dew
on Wed, Jan 20 2010 15:09

Pingback from  Dew Drop – January 20, 2010 | Alvin Ashcraft's Morning Dew

?????? ?? Microsoft Silverlight » ???????????????????? ???????????? ?? Expression Blend wrote ?????? ?? Microsoft Silverlight &raquo; ???????????????????? ???????????? ?? Expression Blend
on Wed, Jan 20 2010 18:41

Pingback from  ?????? ?? Microsoft Silverlight   » ???????????????????? ???????????? ?? Expression Blend

Add a Comment

(required)  
(optional)
(required)  
Remember Me?