Binding in TextBoxes does not work

I created a simple TextBox with a link in a pure WPF-Window

<TextBox Name="MyTextBox" Focusable="True" Width="150" Text="{Binding MyText, UpdateSourceTrigger=PropertyChanged}"</TextBox> 

My problem is that the attached property of the string MyText is not updated in any way. If I type a space, the property is updated. If I paste text through the clipboard into a TextBox, the MyText property is updated. But if I type any other character, nothing happens. I registered an event handler for TextChanged for debugging purposes. The event occurs only for the space character and the insert operation, but is not used for other characters.

A few words about my environment: WPF-Window can only be divided into this TextBox. I open this window from within the DLL. The full project was aimed at .Net2, now, due to WPF, on Framework 3.5. I do not know how to make it simpler to find the problem.

+6
wpf binding
source share
2 answers

You mentioned Framework 2.0. If your application is based on Windows Forms, you should keep in mind some interaction topics. You tried the following before opening a window:

System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop (YourWindowObject)

Otherwise, try opening a window from a WPF application.

+5
source share

By default, snap mode is one way. This means that it is loaded from the default property, but will not be set. Add β€œMode = Twoway” to your binding (see code snippet) and see if this solves the problem for you.

 <TextBox Name="MyTextBox" Focusable="True" Width="150" Text="{Binding MyText, Mode=Twoway, UpdateSourceTrigger=PropertyChanged}"> </TextBox> 
+1
source share

All Articles