1

编辑:

在 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)...
4

0 回答 0