【发布时间】:2014-10-27 16:36:41
【问题描述】:
我正在开发一个 Windows 8 应用商店应用程序。我创建了以下用户控件:
<UserControl
x:Class="RTV_W8.AnimatedImage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RTV_W8"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl.Resources>
<!-- Animates the rectangle's opacity. -->
<Storyboard x:Name="ContainerGridStoryboard">
<DoubleAnimation
Storyboard.TargetName="MainGrid"
Storyboard.TargetProperty="Opacity"
From="0" To="1" Duration="0:0:5"
AutoReverse="False">
</DoubleAnimation>
</Storyboard>
</UserControl.Resources>
<Grid x:Name="MainGrid" CacheMode="BitmapCache">
<Image Stretch="UniformToFill" x:Name="PictureImage"/>
</Grid>
</UserControl>
用下面的cs文件(这里只展示了一部分)
public AnimatedImage()
{
this.InitializeComponent();
this.Loaded += AnimatedImage_Loaded;
this.PictureImage.Loaded += PictureImage_Loaded;
}
void AnimatedImage_Loaded(object sender, RoutedEventArgs e)
{
this.ContainerGridStoryboard.Begin();
}
我的问题是加载图像时情节提要没有启动。此用户控件在另一个用户控件中使用。我尝试了多种变体试图使动画工作,但没有一个工作。我希望用户控件将其不透明度设置为动画,而不是仅仅拉起。虽然我可以通过断点看到 ContainerGridStoryboard.Begin();被执行,屏幕上什么也没有发生
编辑:在另一个用户控件中,后来在数据模板中使用了女巫,如果我将情节提要应用到它工作的主网格上,用户控件就会被动画化。但是如果我将它应用到第二个网格(包含在主网格中)或任何其他元素上,动画就不起作用。这就是我首先创建动画图像的原因。
【问题讨论】:
-
故事板中可能有一点,您可能需要创建绑定...
-
我已经正确设置了依赖属性(animatedImage 有 Source 属性)和绑定。我可以看到图像(绑定正确)。但图像只是弹出。故事板(女巫应该为网格和图像设置动画)不起作用。
-
用触发器试试...
-
我正在使用适用于 Windows 8 的 Metro 应用程序。触发器可用于 wpf,但不适用于 Metro 应用程序
-
我实际上在 Windows 8 应用程序中有触发器。我试过
但它不起作用
标签: c# windows xaml user-controls