WPF Editable Combobox IsFocused problem - wpf

I am developing a Watermarked ComboBox by modifying the ComboBox ControlTemplate. Everything is fine when the ComboBox is not in an editable mode, but when I change the edit mode to True, the IsFocused property is never set to True. This is because in edit mode, the ComboBox is using a TextBox. This is an exact copy of this StackOverflow question: . There are no responses to that question.
Please drop a line if you know how to solve this, or please point me to links that provide a Watermark ComboBox implementation.
Thanks,
Rey.

You could try to use the IsKeyboardFocused or IsKeyboardFocusWithin instead

Try using the IsFocused or IsKeyboardFocused or IsKeyboardFocusWithin properties of the TextBox control which is within the ComboBox control. The TextBox can be found at e.OriginalSource(TextChangedEventArgs property).
It worked for me.

Related

DatePicker: both textbox and button get keyboard focus?

Is there a way to get focus on both controls in the WPF DatePicker? Setting the Focusable property on both makes neither work.
We would like users to be able to tab to both controls instead of focus only going to the textbox. Thanks!
I got some help on this. I needed to set the KeyboardNavigation.TabNavigation property to "Continue", then it worked. Thanks to Sam for the fix.

Is it possible to make a multine textbox in a Silverlight 4 DataForm?

I know that you can set a textbox as multiline in SL4 by setting the AcceptsReturn field to true. However, if you insert this into a DataField and DataForm, the textbox always shows as a single-line textbox, even if I change the VerticalAlignment to Stretch.
How can I make it multiline?
Use EditTemplte and put Textbox as your DateTemplate.
As you already said, set the Textbox AcceptReturn to true, and that's it.
Sample of DisplayTemplate and EditTemplte you can watch here : (#23:00~)
http://www.silverlight.net/learn/data-networking/data-controls/dataform-control
Please update on how it went.

Writable ComboBox in Silverlight

How can we change a Silverlight ComboBox writable like in Windows Form when we change the DropDown property.
I believe the closest you can get is autocompletebox
ComboBox in Silverlight does not have IsReadonly and IsEditable properties like WPF that allow it to be editable.
You will have to create a custom control or a user control to mimic that behavior.

Wpf combobox text property binding problem

I am trying to bind to a combobox text with the IsEditable property set to true. I have a property in my viewmodel which is bound to the text.
I want to validate on the text being typed in the text of the combobox, and restrict some values that the user is typing in. So some will be allowed, and some not, and these need to set the combobox back to its old value.
I do this in the view model and I have tried setting my text property in my view model explicity to the old value or just ignoring the change and raising that the property has been changed, but for the life of me it will not refresh the text back to the old value.
Is this because the combobox is editable, and it has the text caret and focus somewhere in the text of the combobox.
Basically, I want it to refresh back to the previous text when I restrict some typing in the combobox during in editing. Anyone have any ideas to reset the text back to its old value through the ViewModel. Thanks in advance!
Thanks for your replies. But I could never get it to work instead, I made my own UserControl which comprises a textbox overlayed over a combobox, and manipulate those two controls to meet my needs. A long way to go to solve a simple problem, but it works in the end.
Is the viewmodel property you are binding to created as a DependencyProperty? This is probably the problem you are facing Two-way binding in WPF
If you don't want to create a Dependency property then you need to implement INotifyProperty changed and manually force the update in the Property changed event.
I think this is because of a 'bug' in WPF not refreshing the UI if you change the value of a property in the setter. You can workaround it by implementing an IdentityConverter that force the UI to refresh as per this arcticle.

WPF: Read only say TextBox and binding

Say I have a grid, I click an object and it displays in a detail screen. I don't want the user to edit some data so I set the TextBox as disabled? Will binding work? Basically what I want is the TextBox to be greyed out or disabled? How about it in WPF? Can someone explain?
Yes, binding will work with a disabled textbox. For disabling the textbox you have three options:
Set the IsReadOnly property to true. This will not affect the appearance of the textbox, but will stop the user changing the value inside it.
Set IsEnabled to false. This will gray out the textbox and stop it from receiving focus
Use a label or a textblock. This will place the text on screen without the appearence of being in an editable control at all.
As for binding, this will work the same no matter what you do. Set up the binding as normal in either the Xaml or codebehind and the value will update when the backing property changes as usual (provided you have implemented INotifyPropertyChanged, otherwise it'll only get set once)
There is a IsReadOnly property on the TextBox, just set it to true
I would use a <TextBlock/> or a <Label/> to display static data instead of a <TextBox/>.

Resources