1153/5000
I spent the last two days searching for a solution. Unfortunately, I found nothing, or at least nothing that would explain to me how to manage opening and closing windows.
I am new to programming, maybe that's the main problem.
But, my problem is:
I am doing a small WPF program using caliburn.micro and mwwm. The problem is opening and closing windows.
I would like to do a window management class or something like that, but I don't know how to aproach.
Could you explain to me step by step how to do it? I read the caliburn.micro documentation, but it doesn't explain how to do it.
In general, the situation looks like this:
I have a main window from which you can open several others. When i'm opening a window, the main window disappears. After closing that window, the main menu appears again. I did it with:
'''App.Current.MainWindow.Show();'''
I would like to manage all windows. Opening them and closing. I came to the point that I should do it with Iwindowmanager ... but how? What? Where? I have no idea. Hence the request for a step-by-step explanation.
ps. Forgive me my English.
edit:
757/5000
There's a problem with that, I don't have much code because I don't know how to go about it. And wherever I was looking, I couldn't find a hint.
But of course I will show what I have:
To open one window from the main menu I have this:
IWindowManager manager = new WindowManager();
public MenuView()
{
InitializeComponent();
}
private void ActionButton_OnClick(object sender, RoutedEventArgs e)
{
manager.ShowDialog( new FirstViewModel(), null, null);
this.Hide();
}
To close this window I'm using
App.Current.MainWindow.Show();
this.Close();
but if I use the first part of the code in a window other than the main menu, I don't know how to go back.
Related
i'm relatively new to WPF and i was tasked to convert an old winforms project into a wpf project.
I am using the function App_Startup as the start for the App and i already created a mainwindow for my GUI. Normally you would just do this in the startup:
void App_Startup(object sender, StartupEventArgs e)
{
MainWindow main = new MainWindow();
main.Show();
}
but this does not work for me because it shows a completely new mainwindow and ignores the one i already made. I understand the issue is that App_Startup happens before the mainwindow and its components even get initialized but there has to be a way i can jump into the mainwindow let it initialize itself and its components and make that the window i start in App_Startup, but I just don't know how to do that.
I'm sorry if this is a really easy to solve problem, but i just don't know how to solve it.
Also i'm sorry if the English sucks it is not my first language.
Thank you very much for your answers and help in advance.
Greetings from Germany
Edit:
I found my mistake! I accidentally set the whole content to one string and it looked like it created a new Window but it was the same window with overwritten content. 🤦♂️🤦♂️🤦♂️🤦♂️🤦♂️🤦♂️🤦♂️🤦♂️🤦♂️🤦♂️
Thank you all for trying to help me, but in the end the problem was very different from what I had written in this question.
First, open your App.xaml, then change StartupUri to what you need.
for changing the startup form in WPF projects, open the App.XML file and change the StartupUri String with your new Window.
That should be the trick.
Greetings from Austria ✌
I know I'm a bit underqualified to be on here, but seeing as my teacher is no good, was wondering if you could help with this extremely obscure problem that i have.
In this task, we have been asked to create a quiz through windows form application on c#. To be honest, I actually have no idea what I'm doing and am just trying to follow a booklet my teacher has given me. However, it appears this booklet isn't working, and the problem to obscure to be answered with a youtube video.
The problem I have is that I am running the form, and recieving problems when I click a button to access a different form within the program, and instead of just opening the linked windows form, it appears both forms remain open, regardless of the this.Close(); that I have coded. When both forms are open, I am unable to access the sought after form, as when i attempt to click on it it cuts back to the form where I initially clicked the link label. I realise this is very badly written, and I have no idea what I'm doing compared to you guys, but any input whatsoever would be greatly appreciated.
I have linked screenshots below. Ideally I'd like for the Program to run frmSplashScreen, the timer running out, then frmPlayerLogin, where I would click the link label to access frmPlayerSelectionNew.
Screenshot link: http://imgur.com/a/K6RqE
Edit
I've been asked for the key code to be written here
The code on the frmPlayerLogin Screen relating to the link label is this.
private void lblClickToRegister_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Form myNextScreen = new frmPlayerSelectionNew();
myNextScreen.Show();
this.Close();
}`
The code on Program.cs is as follows
`static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmSplashScreen());
Form myNextScreen = new frmSplashScreen();
myNextScreen.Show();
Application.Run(new frmPlayerLogin());`
You have two problems.
ShowDialog() is modal. That means when you use it, instead of Show(), you are halting further execution until you enter a response and return a DialogResult
myNextScreen.Show();
We can't see the rest of your code from that image, and there's a way to post code on here. If it's more than what I just pointed out, we'll need that to help.
I want to make an application which has another screen in the extended screen in another monitor (or in my case projector), similar to the presenter view in power point.
I want to use C#, and I guess in windows form application or wpf template there is no dual screen application support.
My first guess is to make 2 separate project and connect them, but I'm not sure about it either.
Any idea how to do it, or at least someone has a tutorial related to it?
I've looked at google, but still not sure what the right question to the issue, since google always showed "how to set up dual screen" for users.
Please clarify anything if my question is unclear. Thanks.
The easiest method I can think of is to simply create a second form (assuming you use Window Forms for your project), so you'd have Form1 as the default, and Form2 as your second form.
Run Form1 by default, and then while loading Form1, do something like this:
if(System.Windows.Forms.Screen.AllScreens.Length > 1)
{
Form2 form2 = new Form2();
form2.Show();
}
Then within form2's shown event, set it's position to the second screen (and perhaps maximize it, depending on what you need).
private void Form2_Shown(object sender, EventArgs e)
{
this.Location = Screen.AllScreens[1].Bounds.Location;
this.WindowState = FormWindowState.Maximized;
}
From that point on (and provided you keep a reference to Form2 within Form1), you can easily exchange information between the two forms as needed. You could even expand it to support 3-4 monitors, simply by making multiple Form2's, one for each screen
Warning! This is noob question probably! Sorry in advance.
I'm learning C# (using MS Studio 2013) and I'm having hard time creating some kind of decent navigation in simple desktop program.
Basically what I want is this: MenuStrip with options like "calculate something", "Calculate somethingelse"... and other (that I can easily add later - like dynamic menu on a webpage). If you click first option inside the Form connected with the StripMenu you will get some controls that allows you to do something(like inputs on a webpage). If you click the second all these options will disappear and you will get a fresh set of controls where you can do somethingelse (simply another webpage to play with).
What is the best way to do it (I find it amazing hard to find out :) ). Only way I figured out (more from experience in js then tutorials) is to use show/hide like in javascript/html.
ExamplePanel.Visible = false;
ExampleOtherPanel.Visible = true;
But this doesn't seem right - I think it would be impossible to manage in bigger program (not only in code, but visual designer too - you can only fit that much Panels inside Form).
Any advice? Or at least a link to material where I can find out?
EDIT:
Finaly I gave up and used multiple Forms as sugested in answer.
private void MenuStripExample_Click_1(object sender, EventArgs e)
{
SomeForm SomeForm = new SomeForm();
this.Hide(); //Hide the main form before showing the secondary
SomeForm.ShowDialog(); //Show secondary form, code execution stop until SomeForm is closed
//this.Show(); //You may uncomment this if you want to have the previous Form to get back after you close new one
}
You normaly don't hide and show panels with different layouts. This is not a good design.
If you have complete different navigations/control sets, then create a new Form which is responsible for the control set.
If you don't want to use new Forms take a look at the TabControl.
You may also want to take a look at MDI-Container. You can use a Form as a MDI-Container and display various other Forms as child-elements inside of this container.
I'm using the following to create 'toaster' style pop-ups:
Create popup "toaster" notifications in Windows with .NET
Unfortunately, after the message "disappears", there is still a 'task' in the taskbar. After showing multiple popups, there is a separate 'task' for each popup that was opened, all stacked on top of each other.
How can I close these after the opacity animation has completed?
I wrote my own toast implementation, perhaps you can find use of it! It's very simple, all you do is:
ToastMessage.Show("My message", "My Title");
And you're done! :) I'll keep updating it until I think it's perfect, but modify it as you wish! I'm yet to add things like animations and sound effects.
Here is the link:
GitHub WPFToastMessage
I figured this out and it's pretty easy!
I changed this (minus space at beginning):
< Storyboard>
To this:
< Storyboard Completed="Storyboard_Completed">
Then in the 'properties' pane under events, I double-clicked the new event that was auto-added and got this:
private void Storyboard_Completed(object sender, EventArgs e)
{
}
And simply added:
this.Close();