【发布时间】:2016-08-15 03:45:18
【问题描述】:
我正在尝试在 UWP 用户控件中创建一个简单的动画,但我遇到了错误 无法解析目标名称。代码真的很简单,我觉得我忽略了一些明显的东西,但我想不通。
XAML
<UserControl
...
x:Name="ManipulationMediaViewerControl"
...
>
<UserControl.Resources>
<Storyboard x:Name="ZoomAnimation">
<DoubleAnimation Duration="0:0:0.25" To="4" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="ViewboxHost" d:IsOptimized="True"/>
<DoubleAnimation Duration="0:0:0.25" To="4" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="ViewboxHost" d:IsOptimized="True"/>
</Storyboard>
</UserControl.Resources>
<Grid>
<Viewbox x:Name="ViewboxHost"
ManipulationMode="All"
Width="{Binding ElementName=ManipulationMediaViewerControl, Path=ActualWidth}"
Height="{Binding ElementName=ManipulationMediaViewerControl, Path=ActualHeight}">
<Viewbox.RenderTransform>
<CompositeTransform CenterX="0.5" CenterY="0.5" />
</Viewbox.RenderTransform>
<ContentPresenter />
</Viewbox>
</Grid>
</UserControl>
代码
using Windows.UI.Xaml.Controls;
namespace ManipulationMediaViewer
{
public sealed partial class ManipulationMediaViewer : UserControl
{
public ManipulationMediaViewer()
{
this.InitializeComponent();
}
public void ZoomToFactor()
{
ZoomAnimation.Begin(); // Breaks here
}
}
}
所以我的问题是当我尝试启动ZoomAninmation.Begin(); 时,我得到了异常:
WinRT 信息:无法解析 TargetName ViewboxHost。额外的 信息:未检测到已安装的组件。
我在不同项目中的代码非常相似,但似乎工作正常(它在用户控制之外)。当这不起作用时,我删除了代码并通过 Blend UI 创建了故事板,但它产生了相同的代码。任何帮助表示赞赏!
谢谢!
【问题讨论】:
-
移动
x:Name="ViewboxHost"到<CompositeTransform x:Name="ViewboxHost" CenterX="0.5" CenterY="0.5" /> -
我相信你需要引用控件本身,而不是像here描述的控件的组件
-
哦,这绝对不正确,我都是time,但我也有一个坏习惯,就是没有足够的注意力快速解决问题。我会回过头来,一分钟后真正达到顶峰,对此感到抱歉。
-
好酷。我正在调查它,我不确定它是否相关,但似乎 ContentPresenter 忽略了 ViewBox 的 RenderTransform。不过,这可能是另一个问题
-
您是否尝试过清理和重建您的代码?我已经测试了您的代码,但无法重现您的问题。
标签: c# xaml animation win-universal-app