我有带有Image控件和绑定源的列表框。
我想要什么:当图像被加载时(我认为它是ImageOpened事件?),将不透明度属性设置为0到100. Som应用程序(如Facebook)使用此效果。
图像控件在DataTemplate中,并且有很多列表框项。
如何解决?
P.S。我试图在ImageOpened事件之后创建触发器进行图像控制来改变不透明度属性,但是应用程序在调试器中没有任何显示原因而被粉碎。
答案 0 :(得分:2)
DataTemplate:
<DataTemplate>
<Image Source="{Binding}" Opacity="0" ImageOpened="image_ImageOpened"/>
</DataTemplate>
图片动画:
<phone:PhoneApplicationPage.Resources>
<Storyboard x:Name="Storyboard1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</phone:PhoneApplicationPage.Resources>
ImageOpened处理程序:
private void image_ImageOpened(object sender, System.Windows.RoutedEventArgs e)
{
Storyboard1.Begin();
}
答案 1 :(得分:1)
您最初可以将图片Opacity
设置为零,并附加ImageOpened
处理程序,该处理程序会将Opacity
设为动画。
<DataTemplate>
<Image Source="{Binding}" Opacity="0" ImageOpened="OnImageOpened"/>
</DataTemplate>
ImageOpened
处理程序:
private void OnImageOpened(object sender, RoutedEventArgs e)
{
var opacityAnimation = new DoubleAnimation
{
To = 1,
Duration = TimeSpan.FromSeconds(1)
};
Storyboard.SetTarget(opacityAnimation, (DependencyObject)sender);
Storyboard.SetTargetProperty(opacityAnimation,
new PropertyPath(Image.OpacityProperty));
var storyboard = new Storyboard();
storyboard.Children.Add(opacityAnimation);
storyboard.Begin();
}