停止包含按钮来处理输入-Silverlight [英] Stop containing button from handling input - Silverlight
问题描述
我正在使用一个自定义按钮,其中的内容有时是一个文本框。我这样做是为了进行某种就地编辑,您可以在其中键入文本,然后按Enter键,然后文本框消失,按钮的文本就是键入的内容。
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>
问题是如果您按下< space>或< enter>
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.
推荐答案
仅因为TextBox出现在Button上并不意味着它应该是内部按钮:)
Just because a TextBox appears over a Button does not mean it should be inside the button :)
使用带有自定义控件的自定义控件效果更好,该控件上带有可选的文本框。这样,TextBox将不会干扰按钮的行为。如果将它们都放在一个网格中,您仍然会保留很多动态布局控件。
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.
如果您需要特定帮助,请询问。
这篇关于停止包含按钮来处理输入-Silverlight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!