WPF LocalizationExtensionComboBox LocaBinding NullReference异常OnPropertyChanged of View(MVVM)
我得到了一个ViewModelMain,我在其中更改了当前视图和当前ViewModelsWPF LocalizationExtensionComboBox LocaBinding NullReference异常OnPropertyChanged of View(MVVM),wpf,mvvm,localization,nullreferenceexception,Wpf,Mvvm,Localization,Nullreferenceexception,我得到了一个ViewModelMain,我在其中更改了当前视图和当前ViewModels public ViewModelBase CurrentVm { get; set; } public UserControl Content { get { return _content; } set { _content = value;
public ViewModelBase CurrentVm { get; set; }
public UserControl Content
{
get { return _content; }
set
{
_content = value;
RaisePropertyChanged(() => Content); // this is the Line where i get the Exception
}
}
当我从一个具有LocaBinding的特定视图导航到另一个没有LocaBinding的视图时,会出现此问题
在当前视图中,我有一个带有组合框的locBinding
<ComboBox MinWidth="45" MaxWidth="80" Grid.Column="1" ItemsSource="{Binding AmountUnits.View}" ItemTemplate="{StaticResource NameResourceKeyTextBoxItemTemplate}" />
这一切都很好。。。虽然当我在ViewModelMain中更改视图并引发当前视图的PropertyChanged时,我得到一个NullReferenceException../
不管我的新ViewModel是空的还是复杂的。。。当我更改UserControl内容时,会出现异常..:/
如何在ViewModelMain中更改视图
CurrentVm = new MaterialInputViewModel(mc.NewValue);
Content = new InputView();
在内容设置器中,它会中断
堆栈跟踪:
at WPFLocalizeExtension.Engine.LocBinding.OnPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.OnDataContextChanged(DependencyObject contextElement)
at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
...
如果您需要更多信息,请询问。。。我需要帮助!有急事……:/ 刚刚解决了我的问题 将我的本地化扩展更新到2.1.2版修复了它。。。 以前有过1.x.x的最新稳定版本
CurrentVm = new MaterialInputViewModel(mc.NewValue);
Content = new InputView();
at WPFLocalizeExtension.Engine.LocBinding.OnPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.OnDataContextChanged(DependencyObject contextElement)
at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
...