Search code examples
c#wpfbitmapeffect

How to change BitmapEffect in custom WPF control via C# code


I have a custom control type like: <Grid> ... </Grid> and Grid.BitmapEffect property. How can I change BitmapEffetc in this Control (Grid) via C# code (e.g. on event)?

Code sample - part of custom control:

[...]
<Grid Background="#FFE5AA">
    <Grid.RowDefinitions>
        <RowDefinition Height="62*"/>            
        <RowDefinition Height="15*"/>
        <RowDefinition Height="23*"/>
    </Grid.RowDefinitions>

    <Grid.BitmapEffect>
        <OuterGlowBitmapEffect GlowColor="#459E5A" GlowSize="13" Noise="0" Opacity="0.9" />
    </Grid.BitmapEffect>

    <Border Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" BorderBrush="#F5B903" BorderThickness="1,1,1,1" >
    </Border>
[...]

Then in Window.xaml:

<controls:MyControl Name="Control1" Cursor="Hand" MouseDown="Control1_MouseDown" />

Then in C#:

private void Control1_MouseDown(object sender, MouseButtonEventArgs e)
{
    //there i want to change Control1.BitmapEffect
}

Solution

  • OK, I've got it! I was add an DepencyProperty 'GlowSize' and simply change size of glow via it. :) Works perfect.