一个窗口在另一个窗口中的 VisualBrush
基本上,主窗口打开第二个窗口,比方说选项窗口。所以在选项窗口中我想显示主窗口的视觉效果。我尝试了这个,但没有成功:
<Rectangle Grid.Row="1" Margin="3" Height="100">
<Rectangle.Fill>
<VisualBrush Visual="{Binding Application.Current.MainWindow}" />
</Rectangle.Fill>
</Rectangle>
非常感谢任何帮助。
编辑:
我找到了明显的答案:
windowPreview.Visual = Application.Current.MainWindow;
唯一奇怪的是它再次调用 MainWindow 的 Loaded 事件,并且我那里有一些代码应该仅在 MainWindow 首次加载时运行。我认为它只会显示主窗口的当前实例。有什么解决方法吗?
So basically, the MainWindow opens a second Window, let's say OptionsWindow. So in the OptionsWindow I want to show a visual of the MainWindow. I tried this, but didn't work:
<Rectangle Grid.Row="1" Margin="3" Height="100">
<Rectangle.Fill>
<VisualBrush Visual="{Binding Application.Current.MainWindow}" />
</Rectangle.Fill>
</Rectangle>
Any help greatly appreciated.
EDIT:
I found the obvious answer:
windowPreview.Visual = Application.Current.MainWindow;
The only weird thing is that it calls the Loaded event of the MainWindow again and I have some code there that should only run when the MainWindow first loads. I though it would just show the current instance of the MainWindow. Any workaround on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将加载代码放入 MainWindow 的构造函数中,则每个实例只应调用一次。
我不确定 WPF 对于任何给定窗口多次调用 Load 事件是否是一个错误,但听起来这可能是针对用户关闭并重新加载窗口的情况而设计的......
If you put the load code in the constructor for the MainWindow that should only get called once per instance.
I'm not sure if it is a bug that WPF calls the Load event more than once for any given window, but it sounds like it might be by design for cases where a user closes and reloads the window...