Silverlight Glass Button

Martin Grayson wrote an amazing tutorial about how to create a WPF glass button using blend in his blog. He explained each and everything in very details with the step-by-step instruction. (You can find Tutorial.doc in the sample file of his post.)  I’ve been thinking to create the similiar one for Silverlight since I was using Silverlight 1.1 Alpha (a.k.a Silverlight 2 Alpha). Due to some limitation of Silverlight 1.1, it’s not so easy to create it at that time. After that, I’ve been very busy with my job and couldn’t manage to port it to Silverlight.

Today, I got some time to check his code again and managed to port it to Silverlight. It was very simple. The only difference between the original WPF style and the one that I ported is that I’m using Visual State Manager instead of ControlTemplate.Triggers in this sample. The reason is that Silverlight doesn’t support all kind of WPF triggers (including ControlTemplate.Triggers) except EventTrigger. So, I decided to use VSM in my sample. I hope you find it useful.

Custom ContentTemplate of Glass Button

The following code is the Glassy Button Style. If you like to know the detail, I would recommend you to read Martin’s tutorial.

<Style x:Key="GlassButton" TargetType="Button">
<Setter Property="Background" Value="#FF1F3B53"/>
<Setter Property="Foreground" Value="#FF000000"/>
<Setter Property="Padding" Value="3"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush">
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFA3AEB9" Offset="0"/>
<GradientStop Color="#FF8399A9" Offset="0.375"/>
<GradientStop Color="#FF718597" Offset="0.375"/>
<GradientStop Color="#FF617584" Offset="1"/>
<Setter Property="Template">
<ControlTemplate TargetType="Button">
<Border BorderBrush="#FFFFFFFF" BorderThickness="1,1,1,1" CornerRadius="4,4,4,4">
<Border x:Name="border" Background="#7F000000" BorderBrush="#FF000000" BorderThickness="1,1,1,1" CornerRadius="4,4,4,4">
<RowDefinition Height="0.507*"/>
<RowDefinition Height="0.493*"/>
<Border Opacity="0" HorizontalAlignment="Stretch" x:Name="glow" Width="Auto" Grid.RowSpan="2" CornerRadius="4,4,4,4">
<ScaleTransform ScaleX="1.702" ScaleY="2.243"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="-0.368" Y="-0.152"/>
<GradientStop Color="#B28DBDFF" Offset="0"/>
<GradientStop Color="#008DBDFF" Offset="1"/>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" Grid.RowSpan="2"/>
<Border HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="shine" Width="Auto" CornerRadius="4,4,0,0">
<LinearGradientBrush EndPoint="0.494,0.889" StartPoint="0.494,0.028">
<GradientStop Color="#99FFFFFF" Offset="0"/>
<GradientStop Color="#33FFFFFF" Offset="1"/>


Visual State Manager – MouseOver State

Martin is using Trigger.EnterActions and Trigger.ExitActions of ControlTemplate.Triggers to apply the Mouse Over Style but as I mentioned before, Silverlight doesn’t support those kind of triggers so that Visual State Manager is the best choice to change the style.

You will see the following in “MouseOver” state of VSM.

<vsm:VisualState x:Name="MouseOver">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="glow" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>

Visual State Manager – Pressed State

<vsm:VisualState x:Name="Pressed">

<ColorAnimationUsingKeyFrames Storyboard.TargetName="border" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
<SplineColorKeyFrame KeyTime="0" Value="#CC000000"/>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="shine" Storyboard.TargetProperty="Opacity">
<SplineDoubleKeyFrame KeyTime="0" Value="0.4"/>
<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="glow"
<DiscreteObjectKeyFrame KeyTime="00:00:00">

Note: I haven’t implemented the FocusStates and Disabled state. I will look at those states when I have some more time. You can also send me if you manage to create those missing states too. :)

Enjoy! Silverlighters!!!

19 thoughts on “Silverlight Glass Button

  1. >>Are there any specific terms of use?


    The original WPF version is from Martin Grayson. According to his blog, there is no license attached for that WPF version.

    My ported version is under Cc license. That means you can use any way you like as long as you give me the credit (e.g a link or etc)

  2. I’m not sure why you think those buttons are not clickable. Have you checked the demo? The behavior of that button is exactly the same as Vista Taskbar button. :)

  3. Thank you for your sharing. Very nice and great work. I will use that in the development of my project. Since 1 days I search on the NET an very good tutorial for make buttons like that. And I am very happy. Thank.

  4. This means YOU, personally, really should weight your words SERIOUSLY b e b, and I strongly advice you to delete this written defamation v t s b of both characters and a huge group of people who do not take slander and character assassination like this easily d j z r x. I do not know which organization you have got to back you up, but if you do not care about lawsuits in the multi-million dollar range, fine, just keep on what you are doing n f o w a. If you DO care about spending x-amounts of money to try and defend this CLEARLY written libel, then take my DELETE-advice. Your “Post” is now officially taken both copies and screen-shots of and digitally stored for later use and evidence. This is just a warning. We are antifa, we do not forget.

Leave a Reply

Your email address will not be published. Required fields are marked *