How do I trigger a "TextChanged" event using tablet pc input panel? - c#

I am working with a rather complex WPF control; it is a button that, when pressed, creates a Popup, with a TextBox set as the Popup's content. (If it matters, this popup does not seem to be declared in the XAML, but solely within the complex WPF's XAML.CS
I am trying to use this with Window's handwriting recognition software for tablets (installed by default in Accessories/Tablet PC/Tablet PC Input Panel on my non-tablet Windows 7 install)
When I click the button, the Textbox appears. Typing anything into the textbox will trigger the textbox's "TextChanged" event. However, if I were to use the Input Panel's handwriting recognition, and press "insert", the TextChanged event of the textbox does not get triggered. (The TextInput event on the ComplexControl, however, does)
When I use the Input Panel's "insert" on regular WPF Textboxes, it does trigger the TextChanged event.
I assume that some complication of the nested controls is making the Input Panel not work as expected in the former case but not in the latter case, but due to my relative inexperience with WPF (heck, the WPF control itself is legacy code!) I'm not entirely certain why the one would trigger and not the other.
Any ideas? I'm not sure what code I could provide that would be most helpful.

Related

WinForms Button Click event and similar events depend on focus

I have the next situation:
there is a client app with a Form
the Form contains a few TabControl's
there are different controls on TabPage's of TabControl's
when the user clicks on any control, I need to activate the TabPage that is a parent of a control. For that I use a TabPage Enter event
when the TabPage gets activated, I need to make request to the server app, and I put focus to a hidden TextBox to disable UI
The problem is, when I click on a Button on another TabPage, in TabPage.Enter event handler I take focus to my hidden TextBox, and it seems like Button click event doesn't have enough time to be processed. When I put timer and handle TabPage.Enter event after 100 ms, the Button click event seems to be fired well. Same thing happens to all the controls: CheckBox doesn't get checked, RadioButton too. I wouldn't like to use timer, as that is not a stable solution.
Any ideas how could I make TabPage to process all mouse events before I take focus to hidden TextBox? I tried to use Application.DoEvents(), but that didn't help.
You are using a wrong event for a wrong control for what you are trying to do.
Enter event for TabPage is going to be fired when that page becomes an active control of the current form which might not happen under certain conditions. Instead, you need to use Selecting or Selected event of TabControl, depending on whether you want to cancel switching to a different tab or not (see TabControlCancelEventArgs parameter of Selecting event). In your case, Selecting event would be more appropriate since it won't allow switching to a selected tab until event is complete (unless you're doing an asynchronous request to the server). Additionally, you may no longer need to use the hidden TextBox.
UPDATE
Regarding comments to OP, when you have 2 (or more) TabControls on a form and you want to get notified when you press a button in any tab of a different TabControl, you can use Enter event for TabControl. Use a global variable to store which TabControl was activated in the Enter event and then send server request for a currently active tab of that activate TabControl.
If this doesn't work for your scenario, then you need to carefully examine your workflow and see if it can be improved in relation to what you want to accomplish.

How to see all TriggeredEvents for control

Anyway to view all the events triggered specifically for a ui control.
I have integrated WPF toolkit extended into my application and currently facing an issue where the TimePicker does not trigger the ValueChanged unless it loses focus. that would be understandable but it has buttons in the control that changes the value ... so losing focus is not ideal as I would require to click on another control.
This is the first time I get this type of issue but there is a lot of times where I am not too positive which event I want to use so I just put a bunch of events with breakpoints and see which one gets hit with the ideal moment.
For that reason, I am curious to know if there is any sort of debugger tool or something similar that can register/show all the events being hit without me putting a breakpoint in every event or modifying the controls code ?
If ValueChanged is a RoutedEvent you could use a tool like snoop. http://snoopwpf.codeplex.com/
the events tab will show you events as they are triggered (note that you'll have to check off the event that you want to listen to in the dropdown.

In Winforms, why is validation not being fired after leaving TextBox and entering a DataGridView?

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.

Making a "click-out" event in C#

Is there any simple way to make a method that gets called whenever the user clicks out (or changes focus in some other way) from a text box in C#? I'm not really familiar with the way events are handled in C# - I rely on double-clicking a control to automatically generate the btn_Button_Click method.
Thanks!
Try Control.OnLostFocus, which occurs whenever the control loses focus.
You can get a list of events in the properties window for the control. If its not already visible, display the properties window from the view menu. Then select the control you want to add an event to, click the lightning bolt in the properties window (shows events) and add the event you need.

Can't seem to get Timepicker to work (C# / WPF)

I'm sure I'm missing something very easy here. Pretty much any internet search for a Timepicker for C#/WPF points to this webpage: http://jobijoy.blogspot.com/2007/10/time-picker-user-control.html and as such I figured it would work correctly. However, when I copy/paste this into a user control and run it, the control shows up as it should, but when I click on the digits and press Up or Down, nothing happens. Even in debug mode with a break point on the switch case for the KeyDown event, nothing happens. It's not registering the KeyDown event. It's supposed to focus on the grid that contains the TextBlock, so I tried changing the KeyDown to the TextBlock, but to no avail. I cannot seem to get this to work! :( I'm using Visual Studio 2008.
There is an official Microsoft DateTimePicker control included in the WPF Toolkit. This will be part of the framework in .NET 4.0
I think you're the control is not getting focused, for some reason. I tried it, too, and the event wouldn't fire for me, either. This post might offer some insight. Manually setting focus to the user control in the Loaded event didn't work for me, though.
The only thing that did work for me was doing all of the following:
changing the TextBlock to a TextBox and moving the event there (focus is pretty evident with a TextBox)
changing the cast in the event to FrameworkElement (which is where the Name property comes from) instead of Grid
changing the case to the TextBox's name (instead of the grid's name)
changing the event to a PreviewKeyDown (to get the cursor keys to register)
Of course, this only got the event to fire and register properly, the values don't seem to show up (even before I changed the code), but it handles the specific issue of the event not firing.
There's a DatePicker and a TimePicker in silverlight 4
If you want you can create your own control with those or simply use each one separated.

Categories

Resources