Skip to main content

Microsoft Silverlight

Answered Question Binding the From and To properties of an animation in XAMLRSS Feed

(0)

atm_grifter
atm_grifter

Member

Member

8 points

28 Posts

Binding the From and To properties of an animation in XAML

I have a UserControl that defines a VisualState in XAML where I would like to bind the From and To properties of the DoubleAnimation to properties of the UserControl.  Is this possible?  I can create the Storyboard just fine in the code-behind, but I don't know if I can create those same bindings in the XAML of the UserControl.

Example:

<UserControl x:Class="MyUserControl">
    <Grid>
       <VisualState>   
          <StoryBoard>  
             <DoubleAnimation From="{Binding Prop1}" To="{Binding Prop2}" etc.../>

...

public class MyUserControl : UserControl
{
    public Double Prop1 {get; set;}
    public Double Prop2 {get; set;}
}

 
When I run this I get an exception in the XAML parser.
 

 

atm_grifter
atm_grifter

Member

Member

8 points

28 Posts

Re: Binding the From and To properties of an animation in XAML

So I misspoke. Bindings are the wrong approach here, however the spirit of what I'm trying to do remains, which is to set the 'From' property of an animation to a property that exists on the UserControl in XAML.  I understand why bindings wouldn't work as you can't call SetBinding on an animation object.

Unless I'm missing something, there isn't a way to do this in either Silverlight or WPF correct?
 

Allen Chen – MSFT
Allen Ch...

Star

Star

13862 points

1,803 Posts

Answered Question

Re: Binding the From and To properties of an animation in XAML

Hi

atm_grifter:
Unless I'm missing something, there isn't a way to do this in either Silverlight or WPF correct?

It can be done in WPF but unfortunately in Silverlight binding can only be set on FrameworkElement or it's descendent class.

Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

coryking
coryking

Member

Member

40 points

17 Posts

Re: Binding the From and To properties of an animation in XAML

Hello Allen,

Allen Chen – MSFT:

It can be done in WPF but unfortunately in Silverlight binding can only be set on FrameworkElement or it's descendent class.

 

I'm sure you cannot comment much on this sort of thing, but are there plans for "ElementName" style binding in the RTM, or failing that, ever?  IMHO, the whole property binding thing in WPF is one of the better parts of the framework.  I was stunned to find I could not do "ElementName" style binding in Silverlight and got grumpy having to do all kinds of contortions in my code to get the same effect--it felt like having to use WinForms all over again.  Doing all the binding in XAML really cuts down on the amount of (useless) code you need to write.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities