Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
清除文本框的WPF事件触发器_Wpf_Textbox_Mahapps.metro - Fatal编程技术网

清除文本框的WPF事件触发器

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

所以我有一个文本框:

当按下“清除”按钮时,我想捕捉事件

可能吗

我没有发现任何事件

ClearTextButton只是在文本框上调用Clear。没有引发任何特定事件。您最多只能处理TextChanged事件:


首先,给你的文本框起个名字。然后,在按钮上创建单击事件。当触发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;
 }