user1235555
user1235555

Reputation: 335

Changing image source in code

what i am trying to do is something like this on the mentioned event

    private void image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
            //this.animateIC1.Begin();
        Uri uri = new Uri("Images/1.png", UriKind.Relative);
        ImageSource imgSource = new BitmapImage(uri);
        this.imageBack1.Source = imgSource;
        this.Storyboard1.Begin();
    }

it has an animation which flips the front image and loads the backside image.

so i am not able to achieve the desired output as it shows no image after flipping.

this is my "secret" StoryBoard which is behaving perfectly in ExpressionBlend environment.

    <Storyboard x:Name="Storyboard1">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="imageBack1">
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="90"/>
            <EasingDoubleKeyFrame KeyTime="0:0:2" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="imageBack1">
            <DiscreteObjectKeyFrame KeyTime="0:0:1">
                <DiscreteObjectKeyFrame.Value>
                    <Visibility>Visible</Visibility>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimation Duration="0:0:1" To="90" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="image1" d:IsOptimized="True"/>
    </Storyboard>

Upvotes: 0

Views: 2333

Answers (2)

user1158337
user1158337

Reputation: 59

private void Change_Background1(object sender, EventArgs e)
{
    Uri uri = new Uri("/img/day1.jpg", UriKind.Relative);
    ImageSource imgSource = new BitmapImage(uri);
    this.myImg.ImageSource = imgSource;
} 

Upvotes: 1

Magnus Johansson
Magnus Johansson

Reputation: 28325

Without you showing your secret Storyboard, I would guess that you simply set the image source before your storyboard is started.

I'm guessing that you will need to do something along these lines and handle two image objects.

Upvotes: 0

Related Questions