【发布时间】:2010-10-25 07:01:51
【问题描述】:
我在我的 windows phone 7 应用程序中使用 mvvm-light 工具包。
我认为:
<TextBox Height="78" HorizontalAlignment="Left" Margin="108,33,0,0" VerticalAlignment="Top" Width="313" Text="{Binding MyValue, Mode=TwoWay}" />
<Button Content="Go" Height="78" HorizontalAlignment="Left" Margin="127,252,0,0" Name="button1" VerticalAlignment="Top" Width="213" cmd:ButtonBaseExtensions.Command="{Binding DoCommand}" />
我的视图模型是:
public class MainPageViewModel : ViewModelBase
{
public ICommand DoCommand { get; internal set; }
public MainPageViewModel()
{
DoCommand = new RelayCommand(() =>
{
DoSomethingWith(MyValue);
}, () => true);
}
private const string MyValuePropertyName = "MyValue";
private string _myValue;
public string MyValue
{
get { return _myValue; }
set
{
if (_myValue == value)
return;
_myValue = value;
RaisePropertyChanged(MyValuePropertyName);
}
}
}
在模拟器中,当我在文本框中键入值并单击按钮时,我可以看到我首先在 relaycommand lambda 表达式中进行操作,并带有断点 我看到 MyValue 为空。然后,到达 MyValue 的 setter 中的断点,正确的值进入 MyValue。
我做错了什么?当然,我希望可以在 RelayCommand 之前到达 setter...
提前感谢您的帮助。
【问题讨论】:
标签: windows-phone-7 mvvm-light