Page 1 of 1

ActualWidth used in converter is 0 instead of actual width

Posted: 24 Dec 2021, 18:09
by mdube
Hi,

This was working fine with 3.0.10, but seems broken with 3.1.2. The code works also fine in Blend, so I assume this is a bug in Noesis introduced between 3.0.10 and now.

I have some decorator used to later get the width of some elements.
<Decorator Grid.ColumnSpan="5" x:Name="RefWidth"></Decorator>
Then binding to 'ActualWidth' with a converter to get the negative value, to move the object to the left of the screen. When I put a breakpoint in the Convert method of the converter, the received value is 0.
<Grid.Resources>
   <Storyboard x:Key="StoryBoardEmailInfo">
       <DoubleAnimation Storyboard.TargetName="GridCreateAccount"
                        Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)" 
                        To="{Binding ActualWidth, ElementName=RefWidth, Converter={StaticResource NegativeConverter}}" Duration="0:0:0.5">
           <DoubleAnimation.EasingFunction>
               <PowerEase EasingMode="EaseIn"/>
           </DoubleAnimation.EasingFunction>
       </DoubleAnimation>
   </Storyboard>
</Grid.Resources>
I would love to find a workaround until this gets fixed, else I'll have to revert to 3.0.xx

Thanks

Re: ActualWidth used in converter is 0 instead of actual width

Posted: 30 Dec 2021, 13:06
by sfernandez
Could you please report this issue in our bugtracker?

In the meantime, it should work if you wrap the resources inside a ResourceDictionary node like this:
<Grid.Resources>
  <ResourceDictionary>
    <Storyboard x:Key="StoryBoardEmailInfo">
       <DoubleAnimation Storyboard.TargetName="GridCreateAccount"
                        Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)" 
                        To="{Binding ActualWidth, ElementName=RefWidth, Converter={StaticResource NegativeConverter}}" Duration="0:0:0.5">
           <DoubleAnimation.EasingFunction>
               <PowerEase EasingMode="EaseIn"/>
           </DoubleAnimation.EasingFunction>
       </DoubleAnimation>
    </Storyboard>
  </ResourceDictionary>
</Grid.Resources>

Re: ActualWidth used in converter is 0 instead of actual width

Posted: 30 Dec 2021, 22:08
by mdube
I wrapped into a <ResourceDictionary>, but this still doens't work.

Re: ActualWidth used in converter is 0 instead of actual width

Posted: 30 Dec 2021, 22:17
by mdube
My bad, the converters used in the previous excerpt do work fine, breakpoint placed in the converter code shows 2 calls, one with 0, then one with the actual width. I have multiple use cases on the same xaml page and mistaken some. The code not working is when used in Triggers, where it doesn't reach the breakpoint placed in the converter at all.
            <Grid.Triggers>
                <EventTrigger SourceName="BtnAnonymous" RoutedEvent="Button.Click">
                    <EventTrigger.Actions>
                        <BeginStoryboard x:Name="StoryBoard0">
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="GridSigninButtons"
                                     Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)" 
                                     To="{Binding ActualWidth, ElementName=RefWidth, Converter={StaticResource NegativeConverter}}" Duration="0:0:0.5">
                                    <DoubleAnimation.EasingFunction>
                                        <PowerEase EasingMode="EaseIn"/>
                                    </DoubleAnimation.EasingFunction>
                                </DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Grid.Triggers>

Re: ActualWidth used in converter is 0 instead of actual width

Posted: 30 Dec 2021, 22:33
by mdube
Ok, what worked was to move the Storyboard definition from the EventTrigger to the <Grid.Resources> AND to wrap into <ResourceDictionary>.

Re: ActualWidth used in converter is 0 instead of actual width

Posted: 10 Jan 2022, 18:27
by sfernandez
Added ticket #2234 to solve this issue.