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

时间:2022-10-19 21:45:37

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

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

  • 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. 子窗口应该是用户控件还是窗口?

  3. is there any kind of "MDI framework" I can take advantage of
  4. 有什么样的“MDI框架”我可以利用

  5. is there anything special I have to consider to make sure all windows are constantly updated, e.g. use ObservableCollections, etc.?
  6. 有什么特别之处我必须考虑确保所有窗口都不断更新,例如使用ObservableCollections等?

  7. should I store all global variables as properties in the main window so that the child windows can access them?
  8. 我应该将所有全局变量作为属性存储在主窗口中,以便子窗口可以访问它们吗?

  9. how would you go about "dimming a window" or "blurring a window" in WPF?
  10. 你会如何在WPF中“调暗窗口”或“模糊窗口”?

Any advice welcome.

欢迎任何建议。

1 个解决方案

#1


  1. The child windows should derive from Window, then call Show() on an instance of your class to show the modeless dialog.
  2. 子窗口应该从Window派生,然后在类的实例上调用Show()以显示无模式对话框。

  3. Not that I know of.
  4. 从来没听说过。

  5. 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.
  6. 使用WPF数据绑定来保持所有内容都是最新的 - 您的数据类应该实现INotifyPropertyChanged并通过ObservableCollection公开集合。主窗口和弹出窗口应该具有相同的DataContext对象,这样如果一个屏幕更改对象上的属性,另一个屏幕将自动更新。

  7. 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
  8. 使用模型视图 - 查看模型模式以保持数据和UI完全分离。试试这个工具包:http://blogs.msdn.com/ivo_manolov/archive/2009/05/03/9584900.aspx

  9. There's no real "dim" function, but you can do something like this:
  10. 没有真正的“昏暗”功能,但你可以这样做:

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.

当你想调暗窗口时,将dimElement上的Visibility设置为“Visible”并将其设置为“Collapsed”以适当地取消调暗。

Hope that helps!

希望有所帮助!

#1


  1. The child windows should derive from Window, then call Show() on an instance of your class to show the modeless dialog.
  2. 子窗口应该从Window派生,然后在类的实例上调用Show()以显示无模式对话框。

  3. Not that I know of.
  4. 从来没听说过。

  5. 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.
  6. 使用WPF数据绑定来保持所有内容都是最新的 - 您的数据类应该实现INotifyPropertyChanged并通过ObservableCollection公开集合。主窗口和弹出窗口应该具有相同的DataContext对象,这样如果一个屏幕更改对象上的属性,另一个屏幕将自动更新。

  7. 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
  8. 使用模型视图 - 查看模型模式以保持数据和UI完全分离。试试这个工具包:http://blogs.msdn.com/ivo_manolov/archive/2009/05/03/9584900.aspx

  9. There's no real "dim" function, but you can do something like this:
  10. 没有真正的“昏暗”功能,但你可以这样做:

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.

当你想调暗窗口时,将dimElement上的Visibility设置为“Visible”并将其设置为“Collapsed”以适当地取消调暗。

Hope that helps!

希望有所帮助!