lighten background color on button click per binding

Posted by one of two on Stack Overflow See other posts from Stack Overflow or by one of two
Published on 2012-10-29T16:58:46Z Indexed on 2012/10/29 16:59 UTC
Read the original article Hit count: 252

Filed under:
|
|
|

I want to lighten a buttons background on click. So I did the following:

<converter:ColorLightConverter x:Key="colorLightConverter" />

...

<Style BasedOn="{StaticResource default}" TargetType="{x:Type controls:Button}">            
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:Button}">
                    <ControlTemplate.Triggers>                            
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <SolidColorBrush Color="{Binding Path=Background.Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource colorLightConverter}}" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="Transparent"
                            BorderThickness="0">
                        ...                            
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

The converter:

class ColorLightConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Color color = (Color)value;
            System.Drawing.Color lightColor = ControlPaint.Light(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B));

            return Color.FromArgb(lightColor.A, lightColor.R, lightColor.G, lightColor.B);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

But the converter isn't called when I click the button. I think there is anything wrong with the binding, but I can't see the error...

Can you help me?

Maybe I'm completely wrong. What I basically want to do: When clicking the button, take the current background color and lighten it. Not more...

© Stack Overflow or respective owner

Related posts about wpf

Related posts about xaml