最大限度地减少子窗口在WPF中当所有者窗口儿童的所有者窗口最小化 [英] Minimize Child Window in WPF When Owner Window Of Child's Owner Window Minimizes

查看:136
本文介绍了最大限度地减少子窗口在WPF中当所有者窗口儿童的所有者窗口最小化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口在WPF这是一个窗口的所有者,这是所有其他窗口。

I have a Window in WPF which is the Owner of a Window, Which is the Owner of all the Other Windows.

主要所有者( sideWindow )只是200points的宽度被放置在左边,另一个窗口放置在主窗口的右侧。 sideWindow 有按钮,打开形式,在右侧窗口的子窗口。

The main Owner (sideWindow) is just 200points in Width is placed in the left and the other Window is placed right of the main Window. sideWindow has button which opens form as the child window of the right window.

当我最小化的主窗口( sideWindow )只有右边的窗口最小化,其余的子窗口没有最小化。

When I minimize the mainWindow (sideWindow) only the right window is minimized and the rest child window are not minimized.

我怎样才能做到这一点?

How can I achieve this?

推荐答案

我会做一点点的猜测在这里,因为我真的不知道你的程序的体系结构。我会假设你有两个Windows类:主窗口 SideWindow ,和一个单一的视图模型类的 AppVm 。你必须,如果你有一个不同的设置去适应。

I'll have to do a little bit guessing here, as I don't really know the architecture of your program. I'm going to assume you have two Windows classes: MainWindow and SideWindow, and a single view model class AppVm. You'll have to adapt if you have a different settings.

最简单的解决办法是绑定在的WindowState 这两个窗口的在视图模型的一个属性。确保财产火灾通知。

The simplest solution would be to bound the WindowState of both windows to a single property in the ViewModel. Make sure the property fires notifications.

视图模型类:

class AppVm : INotifyPropertyChanged {
    public event PropertyChangedEventHandler PropertyChanged;
    private WindowState m_state;
    public WindowState state {
        get { return m_state; }
        set { m_state=value; raise("state") }
    }
    private raise(string propname) {
        PropertyChanged(this, new PropertyChangedEventArgs(propname));
    }
    ....
}

现在,在Windows XAML文件,绑定将WindowState到一个在视图模型:

Now, in the Windows XAML files, bind the WindowState to the one on the view model:

<Window ... WindowState="{Binding Path=state,Mode=TwoWay} ...>

请注意我是如何将模式设置为双向。这确保在该州使用点击最小化窗口时被改变,这也将改变虚拟机的价值。这一切。

Note how I set the mode to TwoWay. This ensure that when the state is changed when the using clicking the minimize Window, it will also change the value in the VM. That's all.

现在,如果你的架构不同,你必须去适应。目前尚不清楚你想做的事,当用户最大化窗口(你甚至允许的话)中的一个内容。如果你有两个不同的视图模型类的每个窗口,你可以写下一个更加复杂的路径,假设一个视图引用了另一种观点认为,救STAE变量只有在内部类,再结合语句可以是:路径= OtherVm.state。

Now, if your architecture differs, you'll have to adapt. It isn't clear what you want to do when the user maximize one of the windows (do you even allow it). If you have two different view model classes for each Window, you can write down a more complex path, assuming one view has a reference to the other view, save the stae variable only in the inner class, then the binding statement can be: Path=OtherVm.state.

如果您查看的逻辑比较复杂,它是确定在视图(* .xaml.cs文件)背后的一些code。唯一的规则是,视图模型不应该是知道的观点(theoritically,虚拟机也可以运行一个单元测试视图)中。您可以订阅该视图的事件StateChanged并写下你的逻辑在那里。无论如何,最干净的解决方案是在样品code描述。

If your View logic is more complex, It is OK to have some code behind in the view (*.xaml.cs files). The only rule is that the View Model shouldn't be "aware" of the view (theoritically, the VM can also run a "unit test view"). You can subscribe to the event StateChanged of the View and write down your logic there. Anyway, the cleanest solution is described in the sample code above.

希望这有助于。

这篇关于最大限度地减少子窗口在WPF中当所有者窗口儿童的所有者窗口最小化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆