我有一個ViewModelMain在哪裏我changin我當前視圖和當前ViewModels。WPF LocalizationExtensionComboBox locBinding NullReference異常OnPropertyChanged視圖(MVVM)
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 MinWidth="45" MaxWidth="80" Grid.Column="1" ItemsSource="{Binding AmountUnits.View}" ItemTemplate="{StaticResource NameResourceKeyTextBoxItemTemplate}" />
項目的locBinding模板:
<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>
的屬性上的綁定(在我的視圖模型):
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和的PropertyChanged查看我目前的看法是引發我得到的NullReferenceException ..:/ 它不關心,如果我的新的ViewModel是空或複雜...當我changin我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)
...
,如果您需要了解更多信息,請只問...我需要幫助!其緊迫...:/