Sumel007
Topic Author
Posts: 30
Joined: 19 Mar 2020, 10:50

Inheriting from AnimationTimeLine in ManagedSDK

07 Feb 2022, 15:07

Hi!
I wanted to animate grid column width (which is of type GridLength) from * to 2*. After doing some research I've come to the conclusion that making a custom GridLengthAnimation is probably going to be the best for my use case. I've followed the WPF tutorial here and made my own class inheriting from AnimationTimeLine. However in Noesis the fields/methods CreateInstanceCore, TargetPropertyType and GetCurrentValue that I need to override are not virtual so this approach doesn't work.
Is there some other way I could create my own AnimationTimeLine class or smoothly animate GridLength in Noesis right now?
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Inheriting from AnimationTimeLine in ManagedSDK

07 Feb 2022, 16:46

Inheriting from AnimationTimeline is not supported yet in C#, could you please report it in our bugtracker?
In the meantime you can animate instead an attached property that updates the column width on the property changed callback:
public static class GridHelper
{
  public static float GetColumnWidth(ColumnDefinition def)
  {
    return (float)def.GetValue(ColumnWidthProperty);
  }
  public static void SetColumnWidth(ColumnDefinition def, float value)
  {
    def.SetValue(ColumnWidthProperty, value);
  }
  public static readonly DependencyProperty ColumnWidthProperty = DependencyProperty.RegisterAttached(
    "ColumnWidth", typeof(float), typeof(GridHelper), new PropertyMetadata(1.0f, OnColumnWidthChanged));
    
  private static void OnColumnWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
  {
    ColumnDefinition def = d as ColumnDefinition;
    if (def != null) def.Width = new GridLength((float)args.NewValue, GridUnitType.Star);
  }
}
<DoubleAnimation From="1" To="2" Duration="0:0:1"
  Storyboard.TargetName="col"
  Storyboard.TargetProperty="(local:GridHelper.ColumnWidth)"/>
...
<Grid>
  <Grid.ColumnDefintions>
    <ColumnDefinition x:Name="col"/>
    <ColumnDefinition/>
  </Grid.ColumnDefintions>
 
Sumel007
Topic Author
Posts: 30
Joined: 19 Mar 2020, 10:50

Re: Inheriting from AnimationTimeLine in ManagedSDK

07 Feb 2022, 20:47

Alright, I've added it to the issue tracker (#2260)
 
User avatar
jsantos
Site Admin
Posts: 3918
Joined: 20 Jan 2012, 17:18
Contact:

Re: Inheriting from AnimationTimeLine in ManagedSDK

07 Feb 2022, 20:55

Thank you!

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 7 guests