[英]WPF event trigger for clear TextBox
So i have the TextBox
:所以我有
TextBox
:
<TextBox Controls:TextBoxHelper.ClearTextButton="True"
LostFocus="textboxNewValueCell_LostFocus"
TextChanged="textboxNewValueCell_TextChanged"/>
And when press on Clear
button i want to catch the event
.当按下
Clear
按钮时,我想捕捉event
。
Is it possible ?是否可以 ?
I did not find any event
我没有找到任何
event
The ClearTextButton
simply calls Clear()
on the TextBox
. ClearTextButton
只是在TextBox
上调用Clear()
。 There is no specific event raised.没有引发特定事件。 The best you can do is to handle the
TextChanged
event:您能做的最好的事情是处理
TextChanged
事件:
private void textboxNewValueCell_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox tb = sender as TextBox;
if (tb.Text.Length == 0)
{
//the TextBox was cleared and the Button was maybe clicked...
}
}
First, give your TextBox a name.首先,为您的 TextBox 命名。 Then, create a click event on the Button.
然后,在按钮上创建一个单击事件。 when the click event fires, handle the clearing of the TextBox in the CodeBehind.
当点击事件触发时,处理 CodeBehind 中 TextBox 的清除。
<Grid>
<TextBox x:Name="MyTextBox" Text="Some Text"/>
<Button x:Name="ClearButton" Click="ClearButton_Click"/>
</Grid>
private void ClearButton_Click(object sender, RoutedEventArgs e)
{
MyTextBox.Text = string.Empty;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.