我有一个ViewModelMain,我正在改变当前的视图和当前的ViewModel。
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
}
}
当我从一个具有LocBinding的特定视图导航到另一个没有一个的特定视图时,会出现问题..
在当前视图中,我有一个带有Combobox的locBinding
<ComboBox MinWidth="45" MaxWidth="80" Grid.Column="1" ItemsSource="{Binding AmountUnits.View}" ItemTemplate="{StaticResource NameResourceKeyTextBoxItemTemplate}" />
项目模板:
<DataTemplate x:Key="NameResourceKeyTextBoxItemTemplate" >
<StackPanel>
<StackPanel.Resources>
<lex:LocExtension x:Key="LocalizedHeader" x:Name="LocalizedHeader"/>
</StackPanel.Resources>
<Engine:LocBinding Source="{Binding Name, Mode=OneWay}" Target="{x:Reference LocalizedHeader}" />
<TextBlock Text="{x:Reference LocalizedHeader}" />
</StackPanel>
</DataTemplate>
绑定的属性(在我的ViewModel中):
private CollectionViewSource _amountUnits;
public CollectionViewSource AmountUnits
{
get { return _amountUnits; }
set { _amountUnits = value;
RaisePropertyChanged(() => AmountUnits);
}
}
AmountUnits.Source =
AmountUnit.GetAll().Select(x => new MaterialInputProp(x.Id, x.TransKey)
{
Name = x.TransKey,
IsSelected = x.IsSelected
}).ToList();
这一切都很好......但是当我在我的ViewModelMain中更改我的View并且当前View的PropertyChanged被提升时,我得到一个NullReferenceException ..:/ 我不关心我的新ViewModel是空的还是复杂的...当我改变我的UserControl内容我得到异常..:/
例如。我如何在ViewModelMain中更改我的视图
CurrentVm = new MaterialInputViewModel(mc.NewValue);
Content = new InputView();
在内容设定中它打破......
StackTrace:
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)
...
如果您需要更多信息,请问...我需要帮助!紧急......:/
答案 0 :(得分:0)
刚刚解决了我的问题...
将我的本地化扩展更新到版本2.1.2修复了它...
之前有1.x.x的最新稳定版本