I have a very odd problem:
My question is this: what is Snoop doing to force the window refresh?
I have tried the following:
window.UpdateLayout()
; window.InvalidateVisual()
; TopMost
to false
, then true
, to trigger a DependencyProperty refresh. 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.
Puzzle solved, use the Dispatcher
select an appropriate priority, see WPF: In an attached property, how to wait until visual tree loaded properly?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.