1. 程式人生 > >(WPF) Textbox 每次輸入觸發事件處理

(WPF) Textbox 每次輸入觸發事件處理

1.  Code behind. 

protected void TextBox1_TextChanged(object sender, EventArgs e)  
{  
   Label1.Text = Server.HtmlEncode(TextBox1.Text);  
}  

2.  Event trigger

      xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"


 

            <i:Interaction.Triggers>
                <i:EventTrigger EventName="
TextChanged"> <i:InvokeCommandAction Command="{Binding StartTextChanged}" /> </i:EventTrigger> </i:Interaction.Triggers>

3.  MVVM ( Prefered)

<TextBox Text="{Binding MyText,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}
"/>