编辑:
在MainPage.xaml.cs
中public MainPageViewModel ViewModel
{
set
{
try
{
DataContext = value;
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Message: {0} \r\n StackTrace: {1}", ex.Message, ex.StackTrace));
}
}
}
在调试时,没有消息框
部署:
消息:对象引用未设置为对象的实例 StackTrace:
at System.Windows.Data.BindingExpression.SendDataToTarget()
at System.Windows.Data.BindingExpression.SourceAcquired()
at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e)
at at System.Windows.WeakDataContextChangedListener.MentorDataContextChanged(Object sender, DataContextChangedEventArgs e)...