Page 1 of 1

Inheriting from AnimationTimeLine in ManagedSDK

Posted: 07 Feb 2022, 15:07
by Sumel007
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?

Re: Inheriting from AnimationTimeLine in ManagedSDK

Posted: 07 Feb 2022, 16:46
by sfernandez
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>

Re: Inheriting from AnimationTimeLine in ManagedSDK

Posted: 07 Feb 2022, 20:47
by Sumel007
Alright, I've added it to the issue tracker (#2260)

Re: Inheriting from AnimationTimeLine in ManagedSDK

Posted: 07 Feb 2022, 20:55
by jsantos
Thank you!