I have my logic of opening a search modal window based on user selection in a combobox. What happens is the modal window opens but the selected item is not reflected in the combobox. i.e Unlike a Windows form, the WPF combobox is not reflecting the newly selected item when the selectionchanged event is fired.
well i would have used the SelectionChangeCommitted in a Winform, i am not finding an equivalent in this case. Am i missing something thats obvious? Thanks!
Are you opening the modal window in the context of the selecteditemchanged event of the combo box? I would recommend opening the modal window using the dispatcher. This will give the bindings time to catch up if that is the issue. Are you binding the selected item of the combo box to a property on a model / view model? If so is this a one way or two way bind?
It would help if you posted some code along with your question.
Related
I'm overriding the OnValidating event in a custom Winforms text box. I'm finding that if the text box (which is bound to an object) has focus and then I give a grid focus using the mouse, the OnValidating event doesn't always get fired. When I first give the grid focus, it gets fired fine. But, if put one of the grid's cell in edit (blinking cursor), from there on out it seems to not get fired when I go back between the text box and grid using the mouse. If I change focus using the tab key, the validating always gets fired. If I give focus to a non-grid control using the mouse, the validation is always getting fired.
I tried to recreate this functionality from scratch in a simple form and I can't recreate the problem. The grid I'm using in the setup where I'm getting the problem is a custom DataGridView with custom column types. I'm wondering if the grid is the problem. But, I don't see how it could affect the text box events. Any ideas?
It probably has to do with the CausesValidation property.
A control's validation is suppressed if focus is going to a control that has CausesValidation set to false. It's just a wild guess, but I'm thinking some control inside the grid has CausesValidation = false;
This property is meant for things like "Cancel" buttons, but can cause lots of confusion.
I have a Window with many items in it, is there a Window or Grid Event to tell if the user has changed any textbox, combobox, radiobutton, checkbutton etc? I don't want to go through each item and add SelectionChanged event as this is just to tell if anything has changed since the data was last saved.
I think you should implement INotifyPropertyChanged interface which notify you once any property changed.
Here is an example that describes "Bind Better With INotifyProperty". This example is for a Windows App, but hope it would give you an idea.
Doing your job in this way is much elegant than adding events for each controls.
So i have a combo box on the main window of my WPF app. I bind a List accessed through a singleton to the ItemSource of the combo box. All is fine. In a child window that the user can open, i have a ListBox bound to the same List in the singleton.
The Problem: when i change the selection of the list box in the child window, i can see the selection change for the combo box on the main window at the same time.
What is causing these two very separate controls to behave like there is some kind of synchronization between them? Is it an issue with binding both controls to the same data object?
If both of your controls have "IsSynchronizedWithCurrentItem" enabled, you could see this issue.
You can find out more about this property here.
You can bind both controls to the same object without having them synchronized, just mark the "IsSynchronizedWithCurrentItem" property as false, and you should be good to go.
I have code that handles the LostFocus event of my controls. It validates the value and in some cases will enable a subsequent control. For instance, there might be a ComboBox that allows a user to select a country. The subsequent ComboBox allows the user to select a state. IF the currently selected country is not the USA, the state ComboBox is disabled. If the user selects "USA" and then tabs out of the combo box, the LostFocus code enables the state ComboBox. However, the State ComboBox does not get focus, instead focus goes to the control that follows the State ComboBox.
I've tried using the PreviewLostKeyboardFocus to handle the event instead with no luck. I'm kind of at a loss as to figuring out someway to hack WPF to get this work. Any suggestions?
try validating when the data changes, not the UI. You can add validation rules that will fire when the property is updated from the binding. Then you can use a style trigger to activate the control in question.
Check this article it should help.
I'm guessing what is happening is it determines the control to tab to before the LostFocus event fires, thereby skipping the State combo box since it is disabled. Here's the information for how focus works in WPF. What you will want to do is in your handler, determine if it should be going to the State combo box next, and programatically focus that element via the FocusManager class.
I have a System.Windows.Forms.ComboBox on a form and I want to capture the event just before the ComboBox's menu is displayed (something like "DroppingDown"). I can't seem to find a suitable event.
Is capturing this type of event possible with a ComboBox?
The ComboBox should have a DropDown Event. If I am not mistaken, this event should fire immediately when the drop down list starts to show.
What exactly are you wanting to accomplish immediately before the drop down shows that necessitates your capturing of such an event?