Thursday, 6 September 2012

WPF change Button and shadow color on mouse over


<Window x:Class="WpfApplication1.Window2"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window2" Height="300" Width="300">
    <Window.Resources>
        <ResourceDictionary>
            <Style TargetType="{x:Type Button}" x:Key="mybutton">
                <Setter Property="Background">
                    <Setter.Value>
                        <SolidColorBrush Color="Cyan"/>
                        <!--<LinearGradientBrush>
                            <GradientStop Color="Cyan" Offset="1"/>
                        </LinearGradientBrush>-->
                    </Setter.Value>
                </Setter>
                <Setter Property="Foreground">
                    <Setter.Value>
                        <SolidColorBrush Color="Black"/>
                    </Setter.Value>                  
                </Setter>
                <Setter Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect BlurRadius="10" Color="Maroon" Direction="270" ShadowDepth="10" RenderingBias="Quality" Opacity="0.5"/>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsFocused" Value="True">
                        <Setter Property="Effect">
                            <Setter.Value>
                                <DropShadowEffect BlurRadius="10" Color="Red" ShadowDepth="10" RenderingBias="Quality" Direction="270" Opacity="0.5"/>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsMouseOver" Value="True"/>
                        </MultiTrigger.Conditions>
                        <Setter Property="Effect">
                            <Setter.Value>                            
                                <DropShadowEffect BlurRadius="10" Color="Violet" ShadowDepth="10" RenderingBias="Quality" Direction="270" Opacity="0.5"/>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Foreground" Value="White"/>
                        <Setter Property="Background" Value="Maroon"/>
                    </MultiTrigger>
                </Style.Triggers>
            </Style>
         
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="button1" VerticalAlignment="Top" Width="75" Style="{StaticResource mybutton}" />
    </Grid>
</Window>

No comments:

Post a Comment