I have 2 WPF windows. Both the windows have textboxes and combo boxes. Upon entering data into Window1, the user presses a "Next" button and Window2 is loaded. Window2 has a "Back" button which will reload Window1 incase the user wants to change some values. Since it is the same session, I want the last entered values in window1 to appear when the "Back" button in Window2 is pressed. How should I go about doing it in C# or XAML?
you have to take one property in window 1 like
public string ChangeValue { get; set; }
when you press back buttion at that time you can set the property value using instance of window 1
instanceofWindow1.ChangeValue="Value";
Each window should have its own ViewModel. These contains the values you type in the windows. If you click next (and destroy the first window) the you should implement some kind of save method (ICommand that is invoked when clicking on Next) that saves the current state of the ViewModel to a model class (or a database or a text file ...). When you click back you have to reload the model, connect it with the ViewModel and show the Window1.
It seams you are not familiar with WPF, maybe the links from another answer might help you to get started: https://stackoverflow.com/a/2034333/1015350
Furthermore you should get into the topics:
MVVM
ICommands
Databinding
Rule of thumb: Your code behind file should contain nothing. This is all done by databinding.
Related
So basically, I have a C# winform and it has multiple pages (which are different forms) when going to one page to another it closes the previous form/page. However, I have a “Settings” page and on that form I have a toggle button. That toggle button changes the text of a label on form1. If I force the form the open while the “settings” form is open, the text changes. However, I do NOT want that form to actually open I just want the text to change but when I take out the form1.Show(); , and just toggle the button off and switch back to form1 the text is the original and when switching back to settings, the toggle button has re-enabled itself. I cannot figure this out.
This may sound like a really silly question but I've noticed that the Click behaviour of my custom buttons differ when I inherit my class from a Button or UserControl.
I'm developing some controls with a customized look, among others, a button. The default user control class declaration is like this:
public partial class cButton : UserControl
After I added all of the GUI stuff, I added it to my form and tested the click-behaviour.
When I click the button in rapid succession, it only registers ever other click, not even every other click. I thought there is something wrong with the test code, but when I copied the exact code to a normal Winforms button, it registered every click no matter how fast.
Edit: the user control registers every click if I don't click to fast i.e. I wait a few seconds between every click.
I changed my custom control's decleration to inherit from the button class and made absolutely no other changes to any code:
public partial class cButton : Button
When I did my click-test the custom button behaved well, like a winforms button, not missing a click.
Just to test things, I added a list box to my form and added the same test code to its click event and it acted like a non-button, only registering a click every now and then.
I thought a click is supposed to be handled consistently, but apparently it's not that simple.
The question I have arising from this:
What does a button do differently and what could I do to ensure proper
click-behaviour when it is not possible to inherit from a Button?
Your custom UserControl is differentiating between single clicks and double clicks.
To make it operate like a button, you need to set the StandardDoubleClick control style so that when the user clicks twice in rapid succession, the control registers two single clicks and raises two click events, and not a double click event.
Within the constructor add the following statement:
this.SetStyle(ControlStyles.StandardDoubleClick, false);
I think the issue you're experiencing is that if you click the button too fast it registers as a double-click instead of a click. You can check this by writing to your output on double-click so that if your codes doesn't fire, check to see if double-click event did.
I am facing a problem in my application. There are multiple forms which can be accessed by quick setup button in the home page,which contains next and back buttons.
And in the last form there is a finish button, which when clicked goes to another form named Scoreboard. The scoreboard form is having a user control which have home button, setting etc.
When I click on home button it goes back to home page and then when the user clicks the quick setup again, I needs to retain the previous values in the form instead of creating new instance.
In the finish button i am using this code :
Scoreboard sc = new Scoreboard();
sc.show();
this.hide();
Any suggestions ?
There are a couple of ways that you can go. The first is since you are loading your Scoreboard form from the same button you can just subscribe to the Scoreboard Forms FormClosing Event and use public properties to get the information back into your parent form, you could then pass that information back to the ScoreBoard when you create the Form. Your other option would be to use UserSettings to persist your values in between sessions.
I'm taking a whack at WPF and trying to learn as I go. I'd appreciate any advice offered.
I've got a Window that has a Page attached to it (through a Frame on the Window). When you press a button on the Page, I want a custom window to pop up to present several custom options and be displayed in a manner of my choosing (I'm thinking right now I want it to be a grid but that may change as I go on). When selected, the modal window will disappear and return to the calling method (button press from the Page) the value of the selected choice.
I don't want the standard windows dialog box with the options of yes, no, okay, cancel, or anything like that. This is truly just a custom popup that returns a value to the caller when the user makes their selection on the popup.
Create a new Window subclass, which you can layout however you like. Then in your button click event handler, display it modally using myModalWindow.ShowDialog();. You can then have a property on the window class which you can access after it closes in order to access result data, i.e.:
myModalWindow.ShowDialog();
var data = myModalWindow.SomeResultProperty;
If you really want to have something returned from a method, I suppose you could create your own public method on your window class which internally calls ShowDialog() and then returns a value.
I'm creating a simple clipboard manager application. It monitors the content of a clipboard. When a change occurs (throu the win api message loop) it fires up a method to capture current content of clipboard and creates new object called clipboarditem. Next its building a ContextMeuStrip which consits of several clipboarditems created previously. The items menu is accessed by a hotkey. It shows up this menu on certain position of the screen itemsMenu.Show(caretPosition);, with .Focus(), I want it to make it disappear after it loses the focus (eg. clicking somehwere else on the screen or switch applications by alt-tab). Found an event OnLoseFocus but I dont think its working properly because the menu wont even show up.
How to make ContextMenuStrip disappear after loosing focus and how to prevent from showing ContextMenuStrip in taskabr ?
Sorry for my language skills :)
From a very quick look at the events that ContextMenuStrip contains, have you tried the "MouseCaptureChanged" event? It may help you with the losing focus issue.
For the showing in the taskbar issue, have you set "ShowInTaskbar" to false on the form you have your ContextMenuStrip (if you have it on a form)?