清除文本框的WPF事件触发器
所以我有一个文本框: 当按下“清除”按钮时,我想捕捉事件 可能吗 我没有发现任何事件ClearTextButton只是在文本框上调用Clear。没有引发任何特定事件。您最多只能处理TextChanged事件:清除文本框的WPF事件触发器,wpf,textbox,mahapps.metro,Wpf,Textbox,Mahapps.metro,所以我有一个文本框: 当按下“清除”按钮时,我想捕捉事件 可能吗 我没有发现任何事件ClearTextButton只是在文本框上调用Clear。没有引发任何特定事件。您最多只能处理TextChanged事件: 首先,给你的文本框起个名字。然后,在按钮上创建单击事件。当触发click事件时,处理CodeBehind中文本框的清除 <Grid> <TextBox x:Name="MyTextBox" Text="Some Text"/> <Button
首先,给你的文本框起个名字。然后,在按钮上创建单击事件。当触发click事件时,处理CodeBehind中文本框的清除
<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;
}
ClearTextButton attached属性负责将按钮添加到文本框中……这不是问题所在。
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...
}
}
<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;
}