我正在动态绑定到Image控件的source属性。
<Image x:Name="ThumbnailImage" Stretch="Fill" Source="{Binding Thumbnail}"/>
缩略图是一个URL。我对这种方法有两个问题:
我想在使用URL下载的图像即将显示时进行动画制作。我正在使用此代码:
<Grid.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="ThumbnailImage"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)"
Duration="0:0:0.5" From="1" To="0" />
<DoubleAnimation
Storyboard.TargetName="ThumbnailImage"
Storyboard.TargetProperty="Opacity"
Duration="0:0:0.5" From="0" To="1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
它工作得很好,但只有当图像被缓存并在创建图像控件的同一时刻显示时。我认为RoutedEvent“Image.Loaded”仅在创建Image控件时触发,而不是在下载Source属性的图像时触发。
祝你好运
答案 0 :(得分:0)
如何改变整个方法?
在xaml中设置
<image x:name= "imagebox"/>
不透明度为0,将不透明度上的事件更改为100%;
在C#中执行此操作:
BitmapImage image = new BitmapImage(new Uri(URL));
image.Loaded+= (s, e) => //event fires when picture is fully loaded from URL
{
imagebox.Source = image; // give image to picturebox but it won't show because opacity is set to 0
VisualStateManager.GoToState(this, "ShowPicture", true); //This will trigger the Visual State to show picture smoothly
};