【发布时间】:2012-09-26 15:30:04
【问题描述】:
我遇到了空域问题。我的 WPF 应用程序托管了一个 winform 组件。我想在组件加载和长时间活动期间显示一个带有一些“等待”文本的弹出窗口。在这里我得到了我的问题:弹出窗口正确显示,但是当我处理组件的繁忙事件时,我无法更新弹出窗口内容。这里有一些 XAML 代码:
<WindowsFormsHost Name="wfh" Grid.Row="1" Grid.Column="0" ></WindowsFormsHost>
<Popup x:Name="Overlay" AllowsTransparency="True" Placement="Center"
StaysOpen="True"
IsOpen="True"
PlacementTarget="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Grid, AncestorLevel=1}}">
<TextBlock Name="tbWait" Foreground="Red" />
</Popup>
和c#:
myWinformComponent.Event => (s, e) =>
{
tbWait.Text = e.IsBusy ? "Loading..." : string.Empty;
}
我知道 WinForm 和 WPF 的空域问题是什么,但我应该让弹出窗口始终打开,让我在 windowformshost 上显示任何内容。
编辑:我在后面的代码中放置了一些断点,我看到 Text 属性更改正确。此更改不会显示在 UI 中。
您有任何解决方法或解决方案吗? 谢谢各位!
【问题讨论】:
-
@HansPassant 我将尝试使用您链接的问题中报告的解决方案。但我担心我的问题不是 UI 冻结或类似问题,我可以使用 Dispatcher 或 BackgroundWorker 解决。
-
@HansPassant 您链接的答案有效!谢谢!