gpt4 book ai didi

c# - 绑定(bind) DoubleAnimation 值时出错

转载 作者:行者123 更新时间:2023-12-03 10:35:20 27 4
gpt4 key购买 nike

我正在尝试绑定(bind)我的 DoubleAnimation代码隐藏中的 c# 变量的属性。

这是我的 XAML:

<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded" >
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard TargetProperty="Left " Name ="PlayAnimation">
<DoubleAnimation From="{Binding StartAmount}" To="{Binding EndAmount}" Duration="0:0:0.050"
AutoReverse="True" RepeatBehavior="Forever"
FillBehavior="Stop"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Window.Triggers>

在主窗口中
public MainWindow()
{
InitializeComponent();
int StartAmount = 50;
int EndAmount = 100;
}

启动程序后,我刚刚收到异常

Cannot animate the 'Left' property on a 'WpfApplication4.MainWindow' using a 'System.Windows.Media.Animation.DoubleAnimation'. For details see the inner exception.



有谁知道为什么会抛出这个异常?

最佳答案

创建一个具有两个属性的类,如下所示:

public class MyClass
{
public int StartAmount { get; set; }
public int EndAmount { get; set; }
}

然后:
public MainWindow()
{
InitializeComponent();
MyClass ms = new MyClass { StartAmount = 50, EndAmount = 100 };
this.DataContext = ms;
}

关于c# - 绑定(bind) DoubleAnimation 值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32360545/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com