Reputation: 368
I created a simple TextBox with a binding in a pure WPF-Window
<TextBox Name="MyTextBox"
Focusable="True" Width="150"
Text="{Binding MyText, UpdateSourceTrigger=PropertyChanged}"</TextBox>
My problem is, that underlaying string property 'MyText' is not updated in any case. If I type a space character, the property is updated. If I paste text through the clipboard into the TextBox, the property MyText is updated. But if I type in any other character, nothing happens. I registered a event handler for TextChanged for debug purposes. The event only occures for the space character and the paste operation, but for no other characters.
Some words about my enviroment: The WPF-Window can be stripped down to just this TextBox. I open this Window from inside a DLL. The complete project was targeted to .Net2, now, due to WPF, to Framework 3.5. I don't know how to make this more simple to find the problem.
Upvotes: 6
Views: 382
Reputation: 5262
By default, the mode of a binding is one way. This means it loads from a property by default, but won't set. Add "Mode=Twoway" in your binding (see code snippet) and see if this resolves your issue.
<TextBox Name="MyTextBox"
Focusable="True" Width="150"
Text="{Binding MyText, Mode=Twoway, UpdateSourceTrigger=PropertyChanged}">
</TextBox>
Upvotes: 1
Reputation: 4577
You mentioned Framework 2.0. If your application bases on Windows Forms, you should keep in mind some interop topics. Have you tried the following before opening the window:
System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(YourWindowObject)
Otherwise try to open your window from a WPF-Application.
Upvotes: 5