[英]With WPF, how does Snoop force a window refresh on a property change?
I have a very odd problem: 我有一个很奇怪的问题:
My question is this: what is Snoop doing to force the window refresh? 我的问题是这样的:Snoop在做什么以强制刷新窗口?
I have tried the following: 我尝试了以下方法:
window.UpdateLayout()
; window.UpdateLayout()
; window.InvalidateVisual()
; window.InvalidateVisual()
; TopMost
to false
, then true
, to trigger a DependencyProperty refresh. TopMost
设置为false
,然后设置为true
,以触发DependencyProperty刷新。 It turns out that Snoop was not doing anything special. 事实证明,史努比没有做任何特别的事情。
If I wait an additional 500 milliseconds, then it works: 如果我再等待500毫秒,则可以:
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? 拼图解决后,使用
Dispatcher
选择适当的优先级,请参阅WPF:在附加属性中,如何等待直到视觉树正确加载?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.