问题
I'm working on a custom button where the content is sometimes a textbox. I'm doing this so I have a sort of edit-in-place where you can type text, hit enter, and then the textbox disappears and the button's text is what was typed.
So as a simple case, you could mock this up like so:
<Button>
<TextBox />
</Button>
The problem is if you hit the <space> or <enter> while typing it'll "click" the button instead of input those keystrokes into the textbox.
Now, like I said, this is a custom button so I can do whatever I need to in the codebehind to get this working.
回答1:
Just because a TextBox appears over a Button does not mean it should be inside the button :)
You are better off with a custom control that has a button with optional Textbox over it. That way the TextBox will not interfere with the button beahaviour. If you put them both in a grid you will still retain a lot of dynamic layout control.
You will just need to expose properties and events of the button (and probably of the TextBox) on your user control.
If you need specific help, just ask.
来源:https://stackoverflow.com/questions/3817418/stop-containing-button-from-handling-input-silverlight