我有一個簡單的WM7頁面,其中包含TextBox
。此外,我將EventToCommand
(a RelayCommand<string>
)分配給此TextBox
,對TextChanged
事件作出反應。爲了測試pourposes,我在頁面的代碼中添加了其他方法TextBox_TextChanged
。命令和TextBox_TextChanged
都用文本框內容打印消息框。MVVM Light太快:)
TextBox
的初始值是"ABC"
。然後按D和:
TextBox_TextChanged
打印ABCD
。- 該命令打印
ABC
。 D缺失。
爲什麼命令如此之快?
命令聲明:
public RelayCommand<string> TextChanged {get; private set;}
命令初始化:
TextChanged = new RelayCommand<string>((s) => MessageBox.Show(s));
命令綁定:
<TextBox x:Name="SearchTextBox" Margin="10,0" TextWrapping="Wrap" Text="{Binding SearchString, Mode=TwoWay}" FontStyle="Italic" TextChanged="SearchTextBox_TextChanged" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding TextChanged, Mode=OneWay}" CommandParameter="{Binding Text, ElementName=SearchTextBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
你可以發佈你的代碼嗎?沒有看到它們是如何結合在一起的,很難確定地知道。 – Oded 2010-05-02 10:08:32
這裏有問題嗎? – 2010-05-02 10:27:16
作者:WM7你的意思是Windows Phone 7? – 2010-05-02 10:54:57