E-Bat
E-Bat

Reputation: 4892

Setting Opacity property for Window Image Background

I have a Window with background image. I want to change image Opacity property from 0 to 1 at button click, and later from 1 to 0, again at button click. I wanted this transition to occur smoothly, that is why I'm using Storyboard.
The following will work but animation is an non-ending cycle, so I'm struggling with stop and resume animation at will. If possibly I want to do this without codebehing support. Advice?

 <Window.Background>
        <ImageBrush x:Name="imgBackground" ImageSource="Resources/Background.png" ></ImageBrush>
    </Window.Background>

        <Button Width="75" Height="21" Content="Go">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="imgBackground"
                                             Storyboard.TargetProperty="Opacity" From="0" To="1" 
                                             BeginTime="0:0:0" AutoReverse="False" >                                
                            </DoubleAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>

Upvotes: 0

Views: 111

Answers (1)

iCode
iCode

Reputation: 1346

Take a look at these examples: https://msdn.microsoft.com/en-us/library/ms753367(v=vs.110).aspx

You probably want a combination of the Duration property and RepeatBehavior property.

Upvotes: 1

Related Questions