I am using a WindowsFormsHost to host a WF ComboBox in my WPF application
I'd like to set the focus of the keyboard to be inside of the ComboBox's TextBox via my C# code
I've tried things like myComboBox.focus() but haven't had any luck
Can anyone point me in the right direction? Thanks
Peek into this question:
Get and restore WPF keyboard focus
TLDR: Consider using Keyboard.Focus(System.Windows.IInputElement element) method.
Here is another article to read.
Related
I have UserControl which is hoseted in ElementHost.
It contains DataGrid
When user presses enter or double clicks the row new window is shown (modalless), and when that window is closed window with ElementHost is activated back. The problem is that DataGrid loses focus.
Snoop showed me that visual tree has the following structure:
AdornerDecorator -> AvalonAdapter -> My UserControl.
Snoop shows that after activation AdornerDecorator has properties
IsFocusable = false
IsFocused = false
IsKeyboardFocused = true
IsKeyboardFocusWithin = true
What is an absolute nonsense to me.
When user hits Tab or arrow keys the first enabled UserControl's element receives focus.
I've read this post and I'm not happy with it:
Focus works differently for WPF and Windows Forms, and there were some
rough edges around here that we were unable to fix. If you have focus
inside a WindowsFormsHost and either minimize/restore the form or show
a modal dialog, the focus inside the WindowsFormsHost may be lost –
the WindowsFormsHost still has focus, but the control inside it may
not.
Now what? Relax and be happy?
And the very disapointing is inability to reproduce the problem in other applications.
Can anyone explain what are the reasons of such a strange behavior?
May be offer some workaround.
It is a known bug: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7d41218e-c2bb-4957-b0b4-aa24efc4d8c2/
So far the official word from Microsoft is the issue I've described
above is an acknowledged bug but will not be fixed for .NET 3.5. Also
this issue won't be fixed in the next version the .NET Framework (.NET
4.0).
(by kainhart)
But unfortunately the reference to connect is dead.
To workaround this bug I had to add IsVmFocused property to my ViewModel and also create my FocusHelper.IsFocused attached property which listens for element's IsFocused property change and bound VM's property.
You can see the xaml in this (task related) SO question: What is a Cached acessor in the context of DataBinding?
I want to set focus to a textbox always. I am creating a application in wpf, in the search page there is a textbox i want to set focus to that textbox always, if the user clicks anywhere in the page the taxtbox should gain the focus. How to achieve this task.
Geetha.
Despite the solution of handling the LostKeyboardFocus and LostKeyboardFocus and set the focus to the same element again using Keyboard.Focus method, you can find a lot of advices and other solutions here
I have an ActiveX control inside a WinForms user control. My WinForms app loves it!
Now, moving over to WPF, I use the user control in a WindowsFormsHost control. Works great..., but I want to treat this control as a single element so the user can neatly hit TAB over the existing WPF controls AND this user control NOT to 'go inside' it. i.e. just treat it as a single control like all the others.
I think what i need is the ability to trap the keys, and in the event handler simply move focus to the next control in the sequence, but I can't seem to trap any keyboard input. Ive tried the WPF PreviewKey.. events and the like, but once the tabbing gets to the control, it seems to stay inside it and WPF events are ignored.
I couldnt find anything on this in many WPF books and the net. Can anyone suggest a way ?
Thanks,
Jack.
Can't you create some sort of a filter by doing a preview mouse down on the panel or window (whatever is the parent of your controls), this way the panel will catch it before the user control and you should set e.handled to true, and if the user control raised the tab event, keep pushing the focus until you get another control. Preview and e.Handled=ture should solve the problem.
Silverlight 4 has a new ContextMenu control in the latest toolkit.
I can't find any examples anywhere on how to reliably use this ContextMenu on a DataGrid row. Theres a tonne of context menus out there but I want to use the new version from the toolkit.
I'd like to be able to set context menus for rows as well as cells.
The only way I've found is to manually create the menu on right click and show it, but I'd like to do it in XAML.
Note: You need to currently use this workaround to avoid binding problems when using ContextMenu in XAML for a datagrid cell.
The developer of the Toolkit's ContextMenu wrote this article, specifically talking about using it with a DataGrid Delay's Blog
You can use this open source multi-level menu and context menu as alternative:
www.sl4popupmenu.codeplex.com
The demo on the main page shows how to do it in code. But you can also create the menu anywhere in your XAML like any other control and then associate it with the Datagrid using the RightClickElements property. The control will then handle everything else for you.
I want to use a Similar control like domainUPDown control in my wpf application.
How to do the using infragistic or any other way.
I need a control like a textbox with up and down button.
How to do it?
That is ok, but i need tat up and down button for mouse click
Thanks,
With Infragistics use the XamNumericEditor control. The Up and Down arrow keys make the value change.