【问题标题】:WPF change duration via codeWPF 通过代码更改持续时间
【发布时间】:2014-07-27 04:35:24
【问题描述】:

大家好,我正在尝试使用以下代码更改 DoubleAnimation 的持续时间:

 private Duration stay = new Duration(TimeSpan.FromSeconds(1));
    public Duration Stay
    {
        get { return stay; }

        set
        {
            if (stay == value) return;
            stay = value;
            OnPropertyChanged("Stay");
        }
    }

    protected virtual void OnPropertyChanged(string propertyName)
    {
        var handler = PropertyChanged;
        if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    }

    public event PropertyChangedEventHandler PropertyChanged;

我得到的错误是:

无法冻结此 Storyboard 时间线树以供跨线程使用。

我的 XAML 如下所示:

<EventTrigger RoutedEvent="Window.Loaded" SourceName="NotificationWindow">
   <BeginStoryboard x:Name="FadeInStoryBoard">
      <Storyboard>
         <DoubleAnimation Storyboard.TargetName="NotificationWindow" From="0.01" To="0.85" Storyboard.TargetProperty="Opacity" Duration="0:0:0.8">
         </DoubleAnimation>
         <DoubleAnimation Storyboard.TargetName="NotificationWindow" From="0.85" To="0" Storyboard.TargetProperty="Opacity" Duration="{Binding Path=Stay}" BeginTime="0:0:20" Name="boxDelay" x:Uid="boxDelay1">
         </DoubleAnimation>
      </Storyboard>
   </BeginStoryboard>
</EventTrigger>
   etc etc.....

【问题讨论】:

    标签: c# wpf vb.net storyboard


    【解决方案1】:

    即使找到了这样的对象,也不会起作用。请参阅此示例:http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.findname.aspx

    最终结果将类似于:

    DoubleAnimation theDA = null;
    object objFound = stackPanel.FindName("dog");
    if (objFound is DoubleAnimation)
    {
        theDA = objFound as DoubleAnimation;
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 2014-10-03
      • 1970-01-01
      • 2021-04-12
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      • 1970-01-01
      • 2013-01-06
      • 2014-03-08
      相关资源
      最近更新 更多