views:

22

answers:

1

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.

A: 

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.

Enough already
You know what? This is better for another reason too - I wanted the textbox to grow beyond the bounds of the button as the user typed. Sometimes it's the simplest thing you overlook! Thanks for the help.
xanadont