I have problem to keep Window on TOP ? I work with MVVM WPF
I have this code in ConfigRole Model:
if (!System.Windows.Application.Current.Windows.OfType<ConfigRole>().Any())
{
ConfigRoleModel configRoleModel = new ConfigRoleModel();
ConfigRole winconfigRole = new ConfigRole();
winconfigRole.DataContext = configRoleModel;
winconfigRole.Show();
winconfigRole.Topmost = true;
winconfigRole.Focus();
}
Here the new Window is Correct, it is on TOP,
but after that, I want to show other Window on TOP from ConfigRoleModel , this is code ConfigRoleModel :
if (!System.Windows.Application.Current.Windows.OfType<ButtonListView>().Any())
{
ButtonListViewModel buttonListViewModel = new ButtonListViewModel();
ButtonListView winconfigRole = new ButtonListView();
winconfigRole.DataContext = buttonListViewModel;
winconfigRole.Show();
winconfigRole.Topmost = true;
winconfigRole.Focus();
}
So ,here I don't have this new Window on TOP! I don't understand! it is the same code like the first ..
I try also with winconfigRole.ShowDialog();
and `Window.activate()
And the same Problem!
How can I fix it?
Thanks
Set the Owner
property the ConfigRole
to the MainWindow
(or whatever window you open it from) and the Owner
property of ButtonListView
to the ConfigRole
window:
if (!System.Windows.Application.Current.Windows.OfType<ButtonListView>().Any())
{
ButtonListViewModel buttonListViewModel = new ButtonListViewModel();
ButtonListView winconfigRole = new ButtonListView();
winconfigRole.DataContext = buttonListViewModel;
winconfigRole.Owner = System.Windows.Application.Current.Windows.OfType<ConfigRole>().FirstOrDefault(); //<--
winconfigRole.Show();
winconfigRole.Topmost = true;
winconfigRole.Focus();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.