ck_russ
Topic Author
Posts: 27
Joined: 20 May 2020, 14:41

Unable to set Storyboard Target in code

06 Aug 2020, 10:03

Here is a sample with an identical storyboard in code behind and XAML. The XAML storyboard works fine, but in the code behind with Noesis I get "Cannot Begin Storyboard, Target not found"
    <StackPanel>
        
        <Button x:Name="XAMLButton" Width="50" Height="50" Background="DarkSeaGreen" Content="XAML">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard Storyboard.Target="{Binding ElementName=XAMLButton}" Storyboard.TargetProperty="Width">
                            <DoubleAnimation To="200" Duration="0:0:2"></DoubleAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>
        
        <Button x:Name="CodeButton" Width="50" Height="50" Click="CodeButton_Click" Background="DarkGreen" Content="Code"/>
        
    </StackPanel>
    
        private void CodeButton_Click(object sender, RoutedEventArgs e)
        {
            DoubleAnimation d = new DoubleAnimation();
            d.Duration = new Duration(TimeSpan.FromSeconds(2));
            d.To = 200;

            Storyboard sb = new Storyboard();
            sb.Children.Add(d);

            Storyboard.SetTarget(sb, CodeButton);
            Storyboard.SetTargetProperty(sb, new PropertyPath("Width"));
            Storyboard.SetTargetName(sb, "CodeButton");

            Debug.Assert(CodeButton.Name == "CodeButton");
            Debug.Assert(Storyboard.GetTarget(sb) == CodeButton);
            Debug.Assert(Storyboard.GetTargetProperty(sb).Path == "Width");
            Debug.Assert(Storyboard.GetTargetName(sb) == "CodeButton");

            sb.Begin();
        }
        
The asserts all pass. And the object is recognized/valid/instantiated in the code behind.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Unable to set Storyboard Target in code

06 Aug 2020, 11:59

I can't check it right now but I think this happens because the Storyboard is created in code and launched with no parameters Begin, we probably have something wrong in our code in that case. Could you please try calling instead
sb.Begin(CodeButton);
 
ck_russ
Topic Author
Posts: 27
Joined: 20 May 2020, 14:41

Re: Unable to set Storyboard Target in code

06 Aug 2020, 12:21

I can't check it right now but I think this happens because the Storyboard is created in code and launched with no parameters Begin, we probably have something wrong in our code in that case. Could you please try calling instead
sb.Begin(CodeButton);
Yip, that's the issue. Works fine when specifying the object as a parameter.
 
ck_russ
Topic Author
Posts: 27
Joined: 20 May 2020, 14:41

Re: Unable to set Storyboard Target in code

06 Aug 2020, 21:18

There's another possibly related issue here as well. It seems that Storyboards are not inheriting their FillBehavior. Here is a XAMLToy example:
<Grid
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Rectangle Width="50" Height="50" Fill="DarkSeaGreen">
    <Rectangle.Triggers>
      <EventTrigger RoutedEvent="Grid.Loaded">
        <BeginStoryboard>
          <Storyboard FillBehavior="Stop" Storyboard.TargetProperty="Width">
            <DoubleAnimation To="200" Duration="0:0:2"/>
          </Storyboard>
        </BeginStoryboard>
      </EventTrigger>
    </Rectangle.Triggers>
  </Rectangle>
</Grid>
The FillBehavior of the parent is ignored by the DoubleAnimation which will behave as if its FillBehavior was HoldEnd.
 
ck_russ
Topic Author
Posts: 27
Joined: 20 May 2020, 14:41

Re: Unable to set Storyboard Target in code

10 Aug 2020, 05:16

Hi, do you plan to get this/these patched up for the next release? I'm always conflicted about whether to report these sort of issues on the forum or in the bugtracker. Thanks.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Unable to set Storyboard Target in code

10 Aug 2020, 12:31

For all questions that turn into bugs/features it is preferable to create a ticket in the bugtracker so we can include them in the roadmap.
Could you please report both as separate issues (Storyboard.Begin() and FillBehavior inheritance)?
 
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Unable to set Storyboard Target in code

11 Aug 2020, 21:02

Thanks for the reports.

Who is online

Users browsing this forum: No registered users and 90 guests