[英]WPF event trigger for clear TextBox
所以我有TextBox
:
<TextBox Controls:TextBoxHelper.ClearTextButton="True"
LostFocus="textboxNewValueCell_LostFocus"
TextChanged="textboxNewValueCell_TextChanged"/>
当按下Clear
按钮时,我想捕捉event
。
是否可以 ?
我没有找到任何event
ClearTextButton
只是在TextBox
上调用Clear()
。 没有引发特定事件。 您能做的最好的事情是处理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...
}
}
首先,为您的 TextBox 命名。 然后,在按钮上创建一个单击事件。 当点击事件触发时,处理 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.