0

I have a very odd problem:

  • In my C# code, if I set the "Topmost" property, the window does not stay on top.
  • However, if I toggle this same property in Snoop, the windows stays on top.

My question is this: what is Snoop doing to force the window refresh?

enter image description here

What I have tried

I have tried the following:

  • window.UpdateLayout();
  • window.InvalidateVisual();
  • Adding a background task to continuously set this property.
  • Setting TopMost to false, then true, to trigger a DependencyProperty refresh.
Community
  • 1
  • 1
Contango
  • 76,540
  • 58
  • 260
  • 305

1 Answers1

0

It turns out that Snoop was not doing anything special.

If I wait an additional 500 milliseconds, then it works:

Task task = Task.Run(
    async () =>
    {
        // Without this delay, the change will not work.
        await Task.Delay(TimeSpan.FromMilliseconds(500));

        Application.Current.Dispatcher.Invoke(
            () =>
            {
                floatingPaneWindow.Topmost = true;
                {
                    if (window.Top < 0)
                    {
                        window.Top = 0;
                    }
                        if (window.Left < 0)
                    {
                        window.Left = 0;
                    }
                }                                               
            });
    });

Of course, adding specific times into an application is very hacky, so I'm currently looking for some method to determine if the window is properly set up.

Update

Puzzle solved, use the Dispatcher select an appropriate priority, see WPF: In an attached property, how to wait until visual tree loaded properly?

Community
  • 1
  • 1
Contango
  • 76,540
  • 58
  • 260
  • 305