I am using an editable ComboBox in wpf but when i try to set focus from C# code, it is only shows selection. but i want to go for edit option (cursor should display for user input).
相关问题
- VNC control for WPF application
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
- How to properly change a resource dictionary
Based on the answer of user128300 above I came up with a slightly simpler solution. In the constructor or ContextChangedHandler the code is waiting for the control to be loaded before putting the focus on the UI element
Then in the focus even handler I select all the text from the start to the end
In xaml the combobox is editable. By selecting all the text when user type a key it is resetting the previous value
Based on Rikker Serg's answer, you can use that code in your constructor (after InitializeComponent) and dispatch it instead of needing to create custom controls or event handlers.
You can try this code:
You might try deriving from ComboBox and access the internal TextBox, like this:
In your code you would use it like this:
This solution slightly dangerous, however, because in upcoming versions of WPF, Microsoft might decide also to add a GotKeyboardFocus event handler (or similar event handlers), which might get in conflict in with the event handler in MyComboBox.