views:

97

answers:

2

I have 2 textBoxes. First is visible the second is not. When keyDown event fires on first textBox I want to fire the same event on 2nd textBox, so it would react same as if user was typing in 2nd textBox.

How can I do that?


EDIT: I know you can do this in Windows.Forums and I was hoping that it can be done here too.

My goal is to have 2 textBoxes with different texts in it, but when user types something in 1st textBox same text should appear in 2nd textBox.

Example: Text in first textBox:

<home>
 <number>75</number>
 <client>John</client>
</home>

Text in second textBox

<home>
 <number id="123">75</number>
 <client id="345">John</client>
</home>

Now user types some new text in first textBox like:

<home>
 <number>150</number>
 <client>John</client>
</home>

And now this new text should appear in 2nd textBox like:

<home>
 <number id="123">150</number>
 <client id="345">John</client>
</home>

And this is only an example for changing values. User can also add new elements, delete them, change order and so on.

I have tried with mapping KeyEventArgs but I loose control for non-standard keys like: "šđžćč<>"

A: 

You cannot mimic the keyboard in the way you seem to want.

AnthonyWJones
Ok, I edited my first post so its more clear what I want to do.
Gapipro
A: 

What you need is add an eventhandler to the textboxes and in that eventhandler update the second textbox value based on the first one and vice versa.

TextChanged

http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.textchanged(v=VS.95).aspx

private void FirstTextBox_TextChanged(object sender, RoutedEventArgs e)
{
    SecondTextBox.Text = FirstTextBox.Text;
}
texmex5
Nope, don't you see that texts are not identical. 1st text doesn't have attributes and the 2nd does. Copying text like this won't work in my case.
Gapipro
Ok but you'd still had to use eventhandlers i think. Maybe some regular expression magic within the eventhandler? replace only text between the given tags <name *></name> ?
texmex5
Tags can change too, and order of them so it is not so simple as it looks like. That is why I wish to do key sync between both textBoxes. It is like the only way to do it.
Gapipro