Stop containing button from handling input - Silverlight

南笙酒味 提交于 2020-01-15 12:42:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!