Wednesday, May 23, 2012

Flat 3D button Style

Note: This is not my original work. Have blogged it here just for my future reference and of course if someone wants to use it.
 
Flat 3D button in WPF using simple gradient brush. For a more sophisticated 3D button go to Dynamic 3D Button

<Page>  
<Page.Resources>
        <!-- A brush for flat 3D panel borders -->
        <LinearGradientBrush x:Key="Flat3DBorderBrush"
                         StartPoint="0.499,0" EndPoint="0.501,1">
            <GradientStop Color="#FFF" Offset="0" />
            <GradientStop Color="#DDD" Offset="0.01" />
            <GradientStop Color="#AAA" Offset="0.99" />
            <GradientStop Color="#888" Offset="1" />
        </LinearGradientBrush>
    </Page.Resources>
    <Grid>
        <!-- A flat 3D panel -->
        <Border
          HorizontalAlignment="Center" VerticalAlignment="Center"
          BorderBrush="{StaticResource Flat3DBorderBrush}"
          BorderThickness="5" Background="#BBB">
            <StackPanel>
                <Label Content="hi" Height="30" Width="50"/>
                <Control Width="100" Height="100"/>
            </StackPanel>
        </Border>
    </Grid>
</Page>

The button will look like this:

For dynamic 3D button - See this post

2 comments:

  1. This works very well!

    How do you change the look when the user presses the button?

    Regards,
    SG

    ReplyDelete
  2. Hi SG,

    Thanks, Little late to answer your query.
    For changing the look u can refer my blog 3d button . It uses control template to do so and is even more attractive. :))

    Regards,
    Esha

    ReplyDelete