vinod kumar

vinod kumar

  • NA
  • 167
  • 6.7k

creating a glass button in wpf

Jan 1 2013 8:20 AM
<Grid>
///adding a resourses

        <Grid.Resources>
            <ControlTemplate x:Key="GlassButton" TargetType="{x:Type Button}">
                <ControlTemplate.Resources>
                    <Storyboard x:Key="Timeline1">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="glow" Storyboard.TargetProperty="(UIElement.Opacity)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                    <Storyboard x:Key="Timeline2">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="glow" Storyboard.TargetProperty="(UIElement.Opacity)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </ControlTemplate.Resources>
                <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">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.507*"/>
                                <RowDefinition Height="0.493*"/>
                            </Grid.RowDefinitions>
                            <Border Opacity="0" HorizontalAlignment="Stretch" x:Name="glow" Width="Auto" Grid.RowSpan="2" CornerRadius="4,4,4,4">
                                <Border.Background>
                                    <RadialGradientBrush>
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform ScaleX="1.702" ScaleY="2.243"/>
                                                <SkewTransform AngleX="0" AngleY="0"/>
                                                <RotateTransform Angle="0"/>
                                                <TranslateTransform X="-0.368" Y="-0.152"/>
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#B28DBDFF" Offset="0"/>
                                        <GradientStop Color="#008DBDFF" Offset="1"/>
                                    </RadialGradientBrush>
                                </Border.Background>
                            </Border>
                            <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">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.494,0.889" StartPoint="0.494,0.028">
                                        <GradientStop Color="#99FFFFFF" Offset="0"/>
                                        <GradientStop Color="#33FFFFFF" Offset="1"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                        </Grid>
                    </Border>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter Property="Opacity" TargetName="shine" Value="0.4"/>
                        <Setter Property="Background" TargetName="border" Value="#CC000000"/>
                        <Setter Property="Visibility" TargetName="glow" Value="Hidden"/>
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Trigger.EnterActions>
                            <BeginStoryboard Storyboard="{StaticResource Timeline1}"/>
                        </Trigger.EnterActions>
                        <Trigger.ExitActions>
                            <BeginStoryboard x:Name="Timeline2_BeginStoryboard" Storyboard="{StaticResource Timeline2}"/>
                        </Trigger.ExitActions>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
            <DataTemplate x:Key="CarouselItemTemplate">
                <StackPanel>
                    <Grid Visibility="{Binding  NormalEmployeePanelVisibility,Mode=TwoWay}">
                    <Grid.Effect>
                        <DropShadowEffect/>
                    </Grid.Effect>
                    <Grid.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0"/>
                            <GradientStop Color="#FF4C4C4C" Offset="1"/>
                        </LinearGradientBrush>
                    </Grid.Background>
                    <Grid.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Grid.RenderTransform>
                    <TextBlock Text="{Binding FIRST_NAME,Mode=TwoWay}"   FontSize="24" Margin="270.333,29.8,251.067,219.2" Background="Transparent" Foreground="White"  Height="44" d:LayoutOverrides="HorizontalAlignment" />
                    <TextBlock Text="{Binding LAST_NAME,Mode=TwoWay}" FontSize="32"  Margin="268.333,72.8,8,165.2" Background="Transparent" Foreground="White"  Height="55" Panel.ZIndex="2" d:LayoutOverrides="HorizontalAlignment" />
                    <TextBlock Text="{Binding RATING,Mode=TwoWay}" 
           
            ScrollViewer.VerticalScrollBarVisibility="Disabled"
            Background="Transparent" FontSize="300"  
            Foreground="#FF4C4C4C" Margin="419.296,-17.7,0.018,0" 
            FontFamily="Felix Titling" FontWeight="Bold" 
            Height="288.2" 
            VerticalAlignment="Top" 
            RenderTransformOrigin="0.5,0.5" 
            Opacity="0.73" >
            <TextBlock.Effect>
            <DropShadowEffect/>
            </TextBlock.Effect>
            <TextBlock.RenderTransform>
            <TransformGroup>
            <ScaleTransform/>
            <SkewTransform AngleX="-11.345"/>
            <RotateTransform/>
            <TranslateTransform X="-30.999"/>
            </TransformGroup>
            </TextBlock.RenderTransform>
                    </TextBlock>
                    <Image Margin="8,8,354.267,24"  Source="{Binding ImageURL}"  Stretch="Fill" Width="200" Height="261">
                        <Image.Effect>
                            <DropShadowEffect/>
                        </Image.Effect>
                    </Image>
                    <Button x:Name="xpass" Foreground="White" Template="{DynamicResource GlassButton}" Visibility="{Binding ButtonVisibility}" Command="{Binding ChangeContentCommand}" CommandParameter="{Binding}" Margin="10 0 0 0"  Content="Enter Password" Height="30.2" HorizontalAlignment="Center" VerticalAlignment="Center" Click="xpass_Click" FontSize="18.667"  Width="140">

                    </Button>
                </Grid>
                    <Grid Width="600" Height="291" Visibility="{Binding DefaultEmployeePanelVisibility,Mode=TwoWay}">
                        <Grid.Effect>
                            <DropShadowEffect/>
                        </Grid.Effect>
                        <Grid.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="Black" Offset="0"/>
                                <GradientStop Color="#FF4C4C4C" Offset="1"/>
                            </LinearGradientBrush>
                        </Grid.Background>
                        <Grid.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform/>
                                <SkewTransform/>
                                <RotateTransform/>
                                <TranslateTransform/>
                            </TransformGroup>
                        </Grid.RenderTransform>
                        <Image  MouseLeftButtonDown="Image_MouseLeftButtonDown" Source="{Binding ImageURL}" Margin="5" Cursor="Hand" Stretch="Fill">
                            <Image.Effect>
                                <DropShadowEffect/>
                            </Image.Effect>
                        </Image>
                    </Grid>
                </StackPanel>
            </DataTemplate>

            <Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}">
                <Style.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
                </Style.Resources>
            </Style>


            <SolidColorBrush x:Key="ListBorder" Color="#828790"/>
            <Style x:Key="ListBoxStyle1" TargetType="{x:Type ListBox}">
                <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
                <Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
                <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
                <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
                <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
                <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
                <Setter Property="VerticalContentAlignment" Value="Center"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBox}">
                            <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true">
                                <ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
                                    <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                </ScrollViewer>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                                </Trigger>
                                <Trigger Property="IsGrouping" Value="true">
                                    <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>



///using the resourses 
 <Button x:Name="xpass" Foreground="White" Template="{DynamicResource GlassButton}"  Margin="10 0 0 0"  Content="Enter Password" Height="30.2" HorizontalAlignment="Center" VerticalAlignment="Center" Click="xpass_Click" FontSize="18.667"  Width="140">

                    </Button>
</Grid>

Answers (2)