adding a fade in and out animation to my floating window

Eduardo Gomez 3,591 Reputation points
2025-03-30T21:30:02.48+00:00

I made a custom control, that floats when I hover a folder

    public sealed partial class CustomFolderPeekData : UserControl {

        public CustomFolderPeekData() {

            InitializeComponent();
        }

        public void UpdateContent(int FolderCount) {

            FileNum.Text = $"Number of files: {FolderCount}";
        }

        public void ShowPanel() {
            Visibility = Visibility.Visible;
        }

        public void HidePanel() {
            Visibility = Visibility.Collapsed;
        }

    }
}

User's image

In my fileWindow I show d hide the floating window

    private void ItemContainer_PointerEntered(object sender, PointerRoutedEventArgs e) {

        if(sender is FrameworkElement container
            && container.DataContext is FolderItem folderItem) {

            string folderName = folderItem.FileName;
            int folderCount = FolderService.GetgcodeItems(folderName).Count;

            // Calculate the position of the hovered item
            var transform = container.TransformToVisual(rootContainer);
            var pos = transform.TransformPoint(new Point
                (0, container.ActualHeight - 36));

            FloatingPanel.UpdateContent(folderCount);

            FloatingPanel.RenderTransform = new TranslateTransform {
                X = pos.X,
                Y = pos.Y
            };

            FloatingPanel.ShowPanel();
        }
    }

    private void ItemContainer_PointerExited(object sender, PointerRoutedEventArgs e) {

        FloatingPanel.HidePanel();
    }
}

I want to add some fade in and fade out animation

I was reading the docs, but I could not figure it out (https://learn.microsoft.com/en-us/windows/apps/design/motion/motion-fade)

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
865 questions
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 21,481 Reputation points Microsoft External Staff
    2025-04-02T03:06:47.73+00:00

    Hello @Eduardo Gomez ,

    Following up on the problem you encountered in the comments, there is nothing wrong with your UserControl animation, it should be that the `folder button (ItemContainer) is covered when the FloatingPanel appears. You need to start the animation effect outside the ItemContainer. I used the following code to test that it works.

    private void myButton_PointerEntered(object sender, PointerRoutedEventArgs e)
    {
        FloatingPanel.UpdateContent(1);
        FloatingPanel.RenderTransform = new TranslateTransform
        {
            X = -100,
            Y = 0
        };
        FloatingPanel.ShowPanel();
        
    }
    private void myButton_PointerExited(object sender, PointerRoutedEventArgs e)
    {
        FloatingPanel.HidePanel();
    }
    

    Since I lack the definition of FolderItem and rootContainer variables, I can only do simple tests. You need to make sure that the FloatingPanel does not cover the folder button below by calculating.Thank you

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.