在 WPF 中创建 MDI 弹出窗口的最佳方法是什么?

发布于 2024-07-18 17:44:31 字数 555 浏览 6 评论 0原文

我需要创建一个原型来测试 WPF 执行以下操作的能力:

  • 一个基本窗口作为该窗口中应用程序的基础,
  • 用户可以单击(例如“添加客户”),然后弹出一个新窗口
    • 弹出窗口很亮
    • 背景中的主窗口变暗
  • 如果用户单击主窗口,则
    • 主窗口变亮
    • 弹出窗口变暗并进入背景
  • 一个窗口中的任何更改我们需要立即在所有窗口中生效,无论亮还是变暗

问题:

  1. 子窗口是否应该是用户控件还是窗口?
  2. 有没有什么类型的“MDI框架”我可以利用,
  3. 有什么特别的我必须考虑以确保所有窗口不断更新,例如使用ObservableCollections等?
  4. 我应该将所有全局变量作为属性存储在主窗口中,以便子窗口可以访问它们吗?
  5. 在 WPF 中如何“调暗窗口”或“模糊窗口”?

欢迎任何建议。

I need to create a prototype to test the ability of WPF to do the following:

  • one base window as the application's base
  • within this window user can click (e.g. on "add customer") and a new window pops up
    • the pop-up window is bright
    • the main window in the background is dimmed
  • if the user clicks on the main window
    • main window becomes bright
    • pop-up window is dimmed and goes into the background
  • any changes in one window we need to take immediate effect in all windows, bright or dimmed

Questions:

  1. should the child windows be user controls or windows?
  2. is there any kind of "MDI framework" I can take advantage of
  3. is there anything special I have to consider to make sure all windows are constantly updated, e.g. use ObservableCollections, etc.?
  4. should I store all global variables as properties in the main window so that the child windows can access them?
  5. how would you go about "dimming a window" or "blurring a window" in WPF?

Any advice welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十秒萌定你 2024-07-25 17:44:31
  1. 子窗口应从 Window 派生,然后在类的实例上调用 Show() 以显示非模式对话框。
  2. 从来没听说过。
  3. 使用 WPF 数据绑定使所有内容保持最新 - 您的数据类应该实现 INotifyPropertyChanged 并通过 ObservableCollection 公开集合,就像您所说的那样。 主窗口和弹出窗口应该具有相同的 DataContext 对象,这样,如果一个屏幕更改该对象的属性,另一个屏幕将自动更新。
  4. 使用模型视图-视图模型模式来保持数据和 UI 清晰分离。 试试这个工具包:
    http://blogs.msdn.com/ivo_manolov/archive/ 2009/05/03/9584900.aspx
  5. 没有真正的“暗淡”功能,但您可以执行以下操作:

代码:

<Window>
  <Grid x:Name="dimElement">
    <Grid Background="Gray" Opacity="0.5" Visibility="Collapsed"/>
    <Grid>
      main content goes here
    </Grid>
   </Grid>
</Window>

当您想要调暗窗口时,将dimElement上的Visibility设置为“Visible”并将其设置为根据需要“折叠”至不暗淡。

希望有帮助!

  1. The child windows should derive from Window, then call Show() on an instance of your class to show the modeless dialog.
  2. Not that I know of.
  3. Use WPF databinding to keep everything up to date - your data classes should implement INotifyPropertyChanged and expose collections through ObservableCollection like you stated. The main window and popup window should have the same object for a DataContext, that way if one screen changes a property on the object the other will be automatically updated.
  4. Use the model view - view model pattern to keep data and UI cleanly separated. Try this toolkit:
    http://blogs.msdn.com/ivo_manolov/archive/2009/05/03/9584900.aspx
  5. There's no real "dim" function, but you can do something like this:

code:

<Window>
  <Grid x:Name="dimElement">
    <Grid Background="Gray" Opacity="0.5" Visibility="Collapsed"/>
    <Grid>
      main content goes here
    </Grid>
   </Grid>
</Window>

When you want to dim a window set Visibility on dimElement to "Visible" and set it to "Collapsed" to un-dim as appropriate.

Hope that helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文