在代码中更改图像源

时间:2012-02-27 12:22:16

标签: c# windows-phone-7

我想要做的就是上述事件

    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();
    }

它有一个动画,可以翻转正面图像并加载背面图像。

所以我无法达到所需的输出,因为它在翻转后没有显示图像。

这是我的“秘密”StoryBoard,它在ExpressionBlend环境中表现完美。

    <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>

2 个答案:

答案 0 :(得分:1)

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;
} 

答案 1 :(得分:0)

如果没有您展示您的秘密故事板,我猜您只需在故事板开始之前设置图像源。

我猜你需要做something along these lines并处理两个图像对象。