Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF Question: Is it possible to start an XAML-FLair Animation from C# Code ? #107

Open
MakeGywer opened this issue Apr 4, 2023 · 3 comments

Comments

@MakeGywer
Copy link

Hi, I´d like to know if it would also be possible to start an XAML-Flair Animation within C# Code ?

I´d like to have Visibility Animation, when Visibilty is set to "Collapsed" or "Hidden".
Maybe there is also a better way, but I have been thinking about implementing a VisibilityConverter that plays a FadeOut / Slide animation when Visibility != Visible. Here I would like to use a XAML-Flair animation. Is that possible?

Thank you in advance!

public class VisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        bool isVisible = (bool)value;
        if (!isVisible)
        {
            // XAML-FLair Animation here
        }
        return isVisible ? Visibility.Visible : Visibility.Collapsed;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
@assassin316
Copy link
Collaborator

Hi @MakeGywer ,

I'll be able to answer your question within the next day or so, I apologize for the delay.

@assassin316
Copy link
Collaborator

Hi again @MakeGywer,

The library is built specifically for animating in Xaml, I haven't tried using it in C# as it was never the intention. Would be something worth trying.

As for animating a collapsing visual, there's a problem with that. As soon as the visibility of the element is Collapsed, it's immediately gone from the UI, can't be animated anymore, and the XamlFlair verifies if an element is Visible before animating it. You would have to animate a "Fade-out" based on a VM binding to achieve the same effect.

It's something I've wanted to add to the library for awhile, but tricky to do because of the immediate "Collapse" of the element. It would have been easy if an event such as BeforeCollapse or BeforeVisibilityChanged existed in the Xaml framework.

I'm definitely open to ideas if you have any.

@MakeGywer
Copy link
Author

Hi @assassin316,

Thanks for your answer.
Yes it´s a pity that there are no events like BeforeCollapse or BeforeVisibilityChanged.
When i have some time, I will try to execute XAML Flair Animations within c# code.

At the moment I have no idea, but if something comes to mind I will let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants