Beyeonics
Topic Author
Posts: 1
Joined: 21 May 2019, 12:28

Animation for displaying and then collapsing a UserControl is not working

21 May 2019, 13:46

I'm trying to display my UserControl for short time when there is a change in a property value. In WPF, I used the following:
    <Grid>
        <Grid.Triggers>
            <EventTrigger RoutedEvent="Binding.TargetUpdated">
                <BeginStoryboard>
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames BeginTime="0:0:0"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                    Value="{x:Static Visibility.Visible}" />
                            <DiscreteObjectKeyFrame KeyTime="0:0:0.5"
                                                    Value="{x:Static Visibility.Collapsed}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>

        <TextBlock Text="{Binding IllumData.Collimat, StringFormat={}{0,3:0}, NotifyOnTargetUpdated=True}"
                   FontSize="22"
                   Foreground="White"
                   Margin="134, 170, 0, 0" />
        <TextBlock Text="{Binding IllumData.Flood, StringFormat={}{0,3:0}, NotifyOnTargetUpdated=True}"
                   FontSize="22"
                   Foreground="White"
                   Margin="20, 422, 0, 0" />

    </Grid>
    
After trying this method in Noesis rendering and not getting the desired result, I tried to use a similar animation in code behind in a handler for PropertyChanged event (I've thought that perhaps NotifyOnTargetUpdated mechanism is not working in Noesis):
private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Storyboard storyboard = new Storyboard();
            ObjectAnimationUsingKeyFrames objAnim = new ObjectAnimationUsingKeyFrames();
            Storyboard.SetTargetName(objAnim, Name);
            Storyboard.SetTargetProperty(objAnim, new PropertyPath(UserControl.VisibilityProperty));

            DiscreteObjectKeyFrame visibleKeyFrame = new DiscreteObjectKeyFrame();
            visibleKeyFrame.KeyTime = TimeSpan.FromSeconds(0);
            visibleKeyFrame.Value = Visibility.Visible;
            objAnim.KeyFrames.Add(visibleKeyFrame);

            DiscreteObjectKeyFrame collapsedKeyFrame = new DiscreteObjectKeyFrame();
            collapsedKeyFrame.KeyTime = TimeSpan.FromSeconds(1);
            collapsedKeyFrame.Value = Visibility.Collapsed;
            objAnim.KeyFrames.Add(collapsedKeyFrame);

            storyboard.Children.Add(objAnim);
            storyboard.Begin(this);
        }
As it turns out, this code is working only if I stop at the beginning of the function with a breakpoint. During uninterrupted execution there is no effect.

Could you help me to find a way in Noesis to show a control and then to collapse it after certain time interval?

Thanks in advance
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Animation for displaying and then collapsing a UserControl is not working

21 May 2019, 14:22

Hi,
I've thought that perhaps NotifyOnTargetUpdated mechanism is not working in Noesis
You're right, Binding.NotifyOnTargetUpdated and Binding.TargetUpdated event are not implemented in Noesis yet. Could you please report it in our bugtracker, it sounds like an interesting feature to have in the future.
As it turns out, this code is working only if I stop at the beginning of the function with a breakpoint. During uninterrupted execution there is no effect.
This is very strange, could you also report this in the bugtracker, I have no clue now what could be happening to work only if you stop in a breakpoint.

In the meantime you may want to use the interactivity PropertyChangedTrigger to fire the animation everytime the binding value changes:
<Grid x:Name="IllumData">

    <Grid.Resources>
        <Storyboard x:Key="ShowIllumData">
            <ObjectAnimationUsingKeyFrames BeginTime="0:0:0"
                                           Storyboard.TargetProperty="Visibility"
                                           Storyboard.TargetName="IllumData">
                <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                        Value="{x:Static Visibility.Visible}" />
                <DiscreteObjectKeyFrame KeyTime="0:0:0.5"
                                        Value="{x:Static Visibility.Collapsed}" />
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
    </Grid.Resources>

    <i:Interaction.Triggers>
        <i:PropertyChangedTrigger Binding="{Binding IllumData.Collimat}">
            <ei:ControlStoryboardAction Storyboard="{StaticResource ShowIllumData}"/>
        </i:PropertyChangedTrigger>
        <i:PropertyChangedTrigger Binding="{Binding IllumData.Flood}">
            <ei:ControlStoryboardAction Storyboard="{StaticResource ShowIllumData}"/>
        </i:PropertyChangedTrigger>
    </i:Interaction.Triggers>

    <TextBlock Text="{Binding IllumData.Collimat, StringFormat={}{0,3:0}, NotifyOnTargetUpdated=True}"
                FontSize="22"
                Foreground="White"
                Margin="134, 170, 0, 0" />
    <TextBlock Text="{Binding IllumData.Flood, StringFormat={}{0,3:0}, NotifyOnTargetUpdated=True}"
                FontSize="22"
                Foreground="White"
                Margin="20, 422, 0, 0" />

</Grid>
Please let me know if that works.

Who is online

Users browsing this forum: No registered users and 0 guests