How to display a popup behind a popup? - c#

I was just curious to know about creating a popup which generates another popup BEHIND it, whenever a button is clicked.
Let me explain more:
I have a button Bu in the main window.
When I click this button, a popup say Pop_a with a button Bu_a should appear.
When I click button Bu_a a popup Pop_b should be opened, but behind Pop_a.

In Pop_a, within the button click handler, call this.Activate() after the line that shows the Pop_b window.
It should look something like this.
public partial class Pop_a : Window
{
public Pop_a()
{
InitializeComponent();
}
private void Bu_a_Click(object sender, RoutedEventArgs e)
{
var pop_b = new Pop_b();
pop_b.Show();
this.Activate();
}
}
This will put Pop_a back on top of all other windows, after Pop_b has been shown.
If you call this.Activate() before calling pop_b.Show(), Pop_a will be put on top, and then Pop_b will be shown, which puts Pop_b on top, so the order of these method calls matters. Show new window, then Activate the window you want on top.

Related

How have 2 active forms at the same time?

I have a mainform with a toolstrip. Buttons on the toolstrip open new sub-forms. These forms are smaller in Y direction than the mainform. They are drawn precisely over the Mainform and you can only see the toolstrip.
Full-size image
Now I want to press another button of the toolstrip to close the current active subform and opens a new sub form. But when I press on such a button, the mainwindow gets drawn over the subform (which is understandable) but the button event doesn not get triggered. Than I need to press the button again to open a new sub form and this is inconvenient.
Used code looks as follows
private void MenuButton_Click(object sender, EventArgs e)
{
menu_.SetDesktopBounds(0, 0, 1024, 668);
menu_.Show();
try { ssp.Close(); } catch { }
help.Hide();
}
How can I let the toolstrip buttons remain active after I open a subform?
Separate toolstrip to another form which will control which form will be visible above him.

how to close a WPF Dialog Window when user try to touch past window screen

Please look at image,
It has two windows, red one opens after green one.
How could I close red windows when user touch green screen?
Also I have using
protected override void OnDeactivated(EventArgs e)
{
base.OnDeactivated(e);
Close();
}
But this works only when user open another application
here is my green window code, that opens red window
MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
Window1 w=new Window1();
w.ShowDialog();
}
I cannot give you a direct answer since I do not do WPF programming, but an approach I use on IOS is to have one big form, the outer part is transparent and
it actually contains one huge button, which is also transparent, only the Window1 is visible. On the button press event close window1.
But I am pretty sure you should have a way to detect click events on the green part and then close the window1. Maybe add some event listener to some component you place on the green part.
See this answer:
how to close a WPF Dialog Window when the user clicks outside it
Here is a answer I copied:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
protected override void OnDeactivated(EventArgs e)
{
base.OnDeactivated(e);
Close();
}
}

Odd Newline Behaviour in c# WPF

I am migrating from Windows Forms in VB to WPF C# and I wrote the following code....
namespace TestWPF
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
OutputBox.Document.Blocks.Clear();
}
private void AcceptButton_Click(object sender, RoutedEventArgs e)
{
OutputBox.AppendText(String.Format("You clicked the button.{0}",Environment.NewLine));
}
}
}
Where OutputBox is a RichTextBox.
Upon running the program and clicking the button a few times I get output like the following....
You clicked the button.You clicked the button.
You clicked the button.
You clicked the button.
Why does the 1st newline not appear, and then it inserts blank lines rather than just moving on to the next line.
If I change the code to
.AppendText(String.format("You clicked the button.{0}OK{0}",environment.NewLine
I get output
You clicked the button.
OKYou clicked the button.
OK
You clicked the button.
OK
What should my code be like to get output....
You clicked the button.
You clicked the button.
You clicked the button.
Instead of Environment.NewLine use "\r". Although I can't find any link now, I think there's a bug in how RichTextBox handles Environment.NewLine

UserControl window won't close

I have a problem with one of my UserControl Windows.
I have a MainWindow and when a specific situatuin appears, another UserControl will open.
It has two Buttons which sends a command and after that it should be closed.
Right now it only opens the Window and sends the command, but doesn't close it afterwards.
I hope you can help me.
Code:
xaml:
C#:
Code to open the UserControl:
Window window = new Window();
window.Content = new MsgBox();
window.ShowDialog();
Button declaration:
public DelegateCommand OkBtn { get; set; }
Buttonfunction added to button:
OkBtn = new DelegateCommand<object>(OkBtnFkt);
In this Buttonfunction there should be something like: window.Close();
What I have tried:
Window.Close();
Sends the Window.close through the dispatcher to the UI
You could set the DialogResult of the window. What you actually have is a window with a UserControl inside. You could make a MsgBoxWindow to derive from Window. Place your control and a Close Button inside. Then if close button is clicked you can set the DialogResult.
https://msdn.microsoft.com/en-us/library/system.windows.window.dialogresult(v=vs.110).aspx
Anyway why don't you use MessageBox?
I found an answer.
This post had the answer for me :
http://www.codeproject.com/Questions/91746/Close-WPF-user-control-inside-WPF-form-application

new window appears under main window

I am writing an application using WPF. I would like such an action: when I press down mouse button on a button, another window appears, when I release mouse button wherever, this window hides. That is my code so far:
XAML:
<Button Margin="0,0,0,0" Name="button_wykres" PreviewMouseUp="button_wykres_PreviewMouseUp" PreviewMouseDown="button_wykres_PreviewMouseDown">
C#:
private void button_wykres_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
omww.Top = this.Top+50;
omww.Left = this.Left +180;
omww.Show();
}
private void button_wykres_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
omww.Hide();
}
The problem is that new window (omww) appears under the main one, but I need it on top. When I tried other events, i.e. button.Click window is showed above the old one, as I want, and that confuses me. However, Click event doesn't meet my needs. I'd be grateful if anybody help me.
As I see it, you have two possible options for making the child Window appear on top of the parent Window. The first was mentioned by #Viv in a comment and that is to set the TopMost property on the child Window to true:
omww.Topmost = true;
The second option would be to set the Owner property of the child Window to the parent Window (if there is a direct relationship between them):
omww.Owner = this; // if called from the parent Window code behind

Categories