最近做一个东西,需要用到多个子窗体层级关系,首先,有一个MainWindow,然后有一个win1和win2甚至更多,我需要达到的控制是,win1选为focus的时候,win2在win1的上面,TopMost的应用是个不错的选择。代码如下:
public partial class MainWindow : Window { Window win1; Window win2; public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { win1 = new Window(); win1.Title = "win1"; win1.Owner = Application.Current.MainWindow; = new Window(); win2.Title = "win2"; win2.Topmost=true; //win2.Owner = Application.Current.MainWindow; Fun(); } void Fun() { win1.Show(); win2.Show(); } }
如有疑问,请加群568055323联系群主。