从主窗口调用时,ChildWindow 将不会显示(Silverlight,C#)
我有一个 Silverlight 应用程序(编辑:具有更高信任度的浏览器外应用程序),它必须打开一个 ChildWindow (用于登录目的)。当我(尝试)从主函数(或主函数中调用的任何函数)调用事件时,使用下面的代码,什么也没有发生。
var credentials = new Credentials();
credentials.Closed += new EventHandler(Credentials_Closed);
credentials.Show();
我尝试使用一个小型测试应用程序,但它也不起作用。但后来我尝试从 Button_Click 事件中调用该事件...令人惊讶的是,它有效!当由 DispatcherTimer 调用时它也可以工作。
我想如果我在另一个线程中启动它也许会起作用,但它没有解决问题...
您的帮助将非常感谢!
菲利普
资料来源: 为什么 Silverlight ChildWindow 不显示?
对于测试程序:www. philippebellefeuille.com/StackOverflow/8074918/BugChildWindowInMain.rar
I have a Silverlight application (edit: an Out-of-browser application with elevated trust) which must open a ChildWindow (for login purpose). When I (try to) call the event from the main (or any function called in the main), with the code below, nothing happens.
var credentials = new Credentials();
credentials.Closed += new EventHandler(Credentials_Closed);
credentials.Show();
I tried with a small test application and it was not working either. But then I tried to call the event from a Button_Click event... surprise, it works ! It also works when called by a DispatcherTimer.
I thought maybe it will works if I start it in another thread but it didn't solve the issue...
Your help will be very appreciated !
Philippe
Source :
Why Won't the Silverlight ChildWindow Display?
For the test program : www.philippebellefeuille.com/StackOverflow/8074918/BugChildWindowInMain.rar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚尝试了您的示例,它既是 UI 线程问题又是“其他问题”:)
计时器版本按原样工作正常(因为 ShowDialog 被推迟)。
newthread 版本由于线程问题而失败。使用我最喜欢的旧辅助方法(OnUiThread)让它工作。同样,它之所以有效,是因为 ShowDialog 被延迟了:
使用这样的调用:
直接调用很有趣,因为它只是失败,即使您使用上面的 showDialog。
原因如下...
App.xaml.cs 执行此操作:
这意味着在构造函数返回之前,MainPage 不是可视化树的一部分!如果子窗口的父窗口不在可视树中,则子窗口将不会显示。
解决方案 - 等待页面加载!
例如
Just tried your sample and it was both a UI threading issue and "something else" :)
The timer version works fine as-is (because the ShowDialog is deferred).
The newthread version fails because of threading. Got it working using my old favorite helper method (OnUiThread). Again it only worked because the ShowDialog is deferred:
with a call like this:
The direct call is interesting as it just fails, even if you use the showDialog above.
The cause is as follows...
App.xaml.cs does this:
That means that the MainPage is not part of the visual tree until after the constructor returns! If the parent of a ChildWindow is not in the visual tree then a ChildWindow will not show.
Solution - wait until the page is loaded!
e.g.