我有一个简单的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