清除/删除文本框的内容随着按钮的Click事件 [英] Clear / Erase TextBox Content With Button Click Event
问题描述
我有以下XAML代码片段:
<文本框X:名称=FilterTB框TextChanged =FilterTB_TextChanged/>
<按钮X:名称=CancelFilterSelectionButton粗细=大胆CONTENT =X/>
我想删除的文本框的内容时,用户presses按钮。
当然从code这样做的背后,是一个简单的任务,但我想只有通过使用XAML来完成它,所以使用触发器。
我试图研究在网上,但我发现任何解决方案uncorrect,或过于迂回的解决方案,所以我想听到一些清洁和紧凑的解决方案。
在这里,我有一个备用分钟,希望这可以帮助,欢呼声。
命名空间;
<$p$p><$c$c>xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:ei="clr-namespace:Microsoft.Ex$p$pssion.Interactivity.Core;assembly=Microsoft.Ex$p$pssion.Interactions"和易peasy。
&LT; StackPanel的方向=横向
的HorizontalAlignment =中心
VerticalAlignment =中心&GT;
&LT;文本框X:名称=ThatThangToClearWIDTH =250/&GT;
&LT;按钮X:名称=ClearThatThangCONTENT =明确指出唐卡保证金=5.0&GT;
&LT;我:Interaction.Triggers&GT;
&LT;我:EventTrigger中事件名称=点击&GT;
&LT; EI:ChangePropertyAction
的TargetName =ThatThangToClear
目标对象={结合的ElementName = ThatThangToClear}
属性名=文字值={X:空}/&GT;
&LT; /我:EventTrigger中&GT;
&LT; /我:Interaction.Triggers&GT;
&LT; /按钮&GT;
&LT; / StackPanel的&GT;
哦,附: - 你真的只需要或者的TargetName
或目标对象
但我既包括为例子的缘故
I have the following XAML snippet:
<TextBox x:Name="FilterTB" TextChanged="FilterTB_TextChanged"/>
<Button x:Name="CancelFilterSelectionButton" FontWeight="Bold" Content="X"/>
I'd like to erase the content of the TextBox when the user presses the Button.
Of course doing so from Code Behind is a trivial task, but I wanted to accomplish it only through the use of XAML, and so using Triggers.
I tried researching on the net, but I either found uncorrect solutions, or overly-convoluted solutions, so I'd like to hear some clean and compact solutions.
Here I had a spare minute, hope this helps, cheers.
namespaces;
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
and easy peasy.
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBox x:Name="ThatThangToClear" Width="250"/>
<Button x:Name="ClearThatThang" Content="Clear That Thang" Margin="5,0">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ei:ChangePropertyAction
TargetName="ThatThangToClear"
TargetObject="{Binding ElementName=ThatThangToClear}"
PropertyName="Text" Value="{x:Null}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
Oh, and P.S. - You really only need either TargetName
OR TargetObject
but I included both for examples sake.
这篇关于清除/删除文本框的内容随着按钮的Click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!