leapold
leapold

Reputation: 43

How to hide windows or open it behind main aplication

I need to open new window behind main screen. This code doesn't work for me. Lets assume I have 2 classes

MainWindow.xaml

 <Grid>
    <Button Click="ButtonBase_OnClick"></Button>
</Grid>
 private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
       Test t=new Test();
        t.Show();
    }

Test class that I need to open behind Main window

<Window x:Class="WpfApplication1.Test"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApplication1"
    mc:Ignorable="d"
    Title="Test" Height="350" Width="525" ShowInTaskbar="False" Visibility="Hidden"   >
<Grid>
    <TextBox/>
</Grid>

I try to use ShowInTaskbar="False" Visibility="Hidden" but it still doesn't work. The problem I can see "Test" windows 1 sec and after it will be unviable(because Visibility="Hidden") .I need to open this windows many times, it will blinks many times. The better solution to open it behind application. Is anyone knows how to do?

Upvotes: 0

Views: 48

Answers (2)

leapold
leapold

Reputation: 43

The final solution for me

if (Application.Current.MainWindow != null)
                {
                    Application.Current.MainWindow.Topmost=true;
                }

Upvotes: 0

mm8
mm8

Reputation: 169200

Try to set the Topmost property of the MainWindow to true:

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
    Test t = new Test();
    t.Show();

    Topmost = true;
}

This should cause the Test window to be displayed "behind" the main window.

Upvotes: 1

Related Questions