0

我有一个 ViewModelMain 我正在更改我当前的视图和当前的 ViewModels。

        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 的特定视图导航到另一个没有 LocBinding 的视图时,就会出现问题。

在当前视图中,我有一个带有组合框的 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中更改我的视图并且我的当前视图的PropertyChanged被提升时,我得到一个NullReferenceException..:/它不在乎我的新ViewModel是空的还是复杂的......当我我正在更改我的用户控制内容我得到了异常..:/

例如。我如何在我的 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)
...

如果您需要更多信息,请询问...我需要帮助!这很紧急... :/

4

1 回答 1

0

刚刚解决了我的问题...

我的本地化扩展更新到版本 2.1.2 修复了它...之前有 1.xx 的最新稳定版本

于 2013-04-03T18:42:34.450 回答