# Problem with WPF animation.Duration= and TimeSpan

**URL:** <https://www.ruby-forum.com/t/problem-with-wpf-animation-duration-and-timespan/160453>\
**Category:** IronRuby\
**Created:** [February 16, 2009, 3:55pm UTC](https://www.ruby-forum.com/t/problem-with-wpf-animation-duration-and-timespan/160453 "2009-02-16T15:55:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [February 16, 2009, 3:55pm UTC](https://www.ruby-forum.com/t/problem-with-wpf-animation-duration-and-timespan/160453/1 "2009-02-16T15:55:20Z")

</div>

Hi all,

Once again I am hitting some unexpected behavior in IronRuby. Might be a  
bug  
😉

> > > animation = System::Windows::Media::Animation::DoubleAnimation.new()  
> > > =\> #System::Windows::Media::Animation::DoubleAnimation:0x000005c

> > > animation.Duration= System::Windows::Duration.new(  
> > > System::TimeSpan.FromSeconds(2))  
> > > =\> #System::Windows::Duration:0x000005e

> > > animation.Duration= System::Windows::Duration.Forever  
> > > =\> #System::Windows::Duration:0x0000060

So far everything works as expected. Now trying to directly set a  
timespan  
which should be possible in C#:

> > > animation.Duration= System::TimeSpan.FromSeconds(2)  
> > > :0: can’t convert System::TimeSpan into System::Windows::Duration  
> > > (TypeError)

ok, automatic conversion seems not yet to work here … but the next  
thing  
is really strange:

> > > animation.Duration= System::Windows::Duration.new(  
> > > System::TimeSpan.FromSeconds(2))  
> > > :0: can’t convert System::TimeSpan into System::Windows::Duration  
> > > (TypeError)

> > > animation.Duration= System::Windows::Duration.Forever  
> > > :0: can’t convert System::TimeSpan into System::Windows::Duration  
> > > (TypeError)

> > > ???

What has already worked now doesn’t any more, depending on the value  
that  
has been set before. You will probably know what is going on.

Cheers,  
– henon

---

<div class="post-metadata">

**Author:** ![Meinrad\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@Meinrad\_R](https://www.ruby-forum.com/u/Meinrad_R)\
**Post date:** [February 17, 2009, 12:23am UTC](https://www.ruby-forum.com/t/problem-with-wpf-animation-duration-and-timespan/160453/2 "2009-02-17T00:23:59Z")

</div>

Crazy. I’ve opened a bug:  
[http://rubyforge.org/tracker/index.php?func=detail&aid=23953&group\_id=4359&atid=16798](http://rubyforge.org/tracker/index.php?func=detail&aid=23953&group_id=4359&atid=16798)

~js

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Meinrad  
Recheis  
Sent: Monday, February 16, 2009 6:34 AM  
To: ironruby-core  
Subject: [Ironruby-core] problem with WPF animation.Duration= and  
TimeSpan

Hi all,

Once again I am hitting some unexpected behavior in IronRuby. Might be a  
bug 😉

> > > animation = System::Windows::Media::Animation::DoubleAnimation.new()  
> > > =\> #System::Windows::Media::Animation::DoubleAnimation:0x000005c

> > > animation.Duration= System::Windows::Duration.new( System::TimeSpan.FromSeconds(2))  
> > > =\> #System::Windows::Duration:0x000005e

> > > animation.Duration= System::Windows::Duration.Forever  
> > > =\> #System::Windows::Duration:0x0000060

So far everything works as expected. Now trying to directly set a  
timespan which should be possible in C#:

> > > animation.Duration= System::TimeSpan.FromSeconds(2)  
> > > :0: can’t convert System::TimeSpan into System::Windows::Duration  
> > > (TypeError)

ok, automatic conversion seems not yet to work here … but the next  
thing is really strange:

> > > animation.Duration= System::Windows::Duration.new( System::TimeSpan.FromSeconds(2))  
> > > :0: can’t convert System::TimeSpan into System::Windows::Duration  
> > > (TypeError)

> > > animation.Duration= System::Windows::Duration.Forever  
> > > :0: can’t convert System::TimeSpan into System::Windows::Duration  
> > > (TypeError)

> > > ???

What has already worked now doesn’t any more, depending on the value  
that has been set before. You will probably know what is going on.

Cheers,  
– henon
