При переключении вкладок в Avalondock возникает System.NullReferenceException

112
21 августа 2019, 00:20

При переключении вкладок периодически возникает System.NullReferenceException К примеру, если переключаться между вкладками "Компоненты" и "Импортированные графики" на какой-то раз возникает ошибка. Самое неприятное, что ошибка то возникает, то нет.

Код главного окна приложения:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" 
    xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
    xmlns:dockctrl="clr-namespace:Xceed.Wpf.AvalonDock.Controls;assembly=Xceed.Wpf.AvalonDock"
    xmlns:view="clr-namespace:Galaxy_Rotation_4.View"
    xmlns:viewmodel="clr-namespace:Galaxy_Rotation_4.ViewModel"
    xmlns:menuVM="clr-namespace:Galaxy_Rotation_4.ViewModel.Menu"
    xmlns:diagramsVM="clr-namespace:Galaxy_Rotation_4.ViewModel.Diagrams"
    xmlns:ic="clr-namespace:Galaxy_Rotation_4.View.ImportedGraphicsControls"
    xmlns:cc="clr-namespace:Galaxy_Rotation_4.View.ComponentControls"
    x:Class="Galaxy_Rotation_4.MainWindow"
    Title="Galaxy Rotation 3" Height="550" Width="1000"
    WindowState="Maximized"
    mc:Ignorable="d"
    x:Name="mainWindow"
    d:DataContext="{viewmodel:MainWindowVM}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition />
        </Grid.RowDefinitions>
        <Menu>
            <!--Меню "Файл"-->
            <MenuItem Header="Файл">
                <MenuItem Header="Выход" Command="{Binding Path=Quit}"/>
            </MenuItem>
            <!--Меню "Вид"-->
            <MenuItem Header="Вид" >
                <MenuItem Header="Графики"  DataContext="{Binding MenuGraphicsViewModel}" ItemsSource="{Binding Items}">
                    <MenuItem.Resources>
                        <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
                            <Setter Property="Command" Value="{Binding Command}" />
                            <Setter Property="Header" Value="{Binding Header}" />
                            <Setter Property="IsCheckable" Value="{Binding IsCheckable}" />
                            <Setter Property="IsChecked" Value="{Binding IsChecked}" />
                        </Style>
                        <HierarchicalDataTemplate DataType="{x:Type menuVM:MenuItemVM}" ItemsSource="{Binding Items}" />
                    </MenuItem.Resources>
                </MenuItem>
                <MenuItem Header="Управление компонентами"
                          IsCheckable="True" IsChecked="{Binding Path=IsVisible, ElementName=controls}" />
                <MenuItem Header="Импорт"
                          IsCheckable="True" IsChecked="{Binding Path=IsVisible, ElementName=importedGraphics}" />
                <MenuItem Header="Среднеквадратичные отклонения"
                          IsCheckable="True" IsChecked="{Binding Path=IsVisible, ElementName=standardDerivations}" />
                <MenuItem Header="Отчет о массах"
                          IsCheckable="True" IsChecked="{Binding Path=IsVisible, ElementName=massReport}" />
            </MenuItem>
            <!--Меню "Настройки"-->
            <MenuItem Header="Настройки">
                <MenuItem Header="Вид кривых"
                          IsCheckable="True" IsChecked="{Binding Path=IsVisible, ElementName=lineDesigner}" />
                <!--<MenuItem Header="Параметры компонентов"/>-->
                <MenuItem Header="Параметры расчетной области" Command="{Binding PlotAreaTuningCommand}"/>
            </MenuItem>
        </Menu>

        <xcad:DockingManager Margin="0" Grid.Row="1"
                             DataContext="{Binding DockManagerVM}"
                             DocumentsSource="{Binding Documents}"
                             AnchorablesSource="{Binding Anchorables}">
            <xcad:DockingManager.LayoutItemContainerStyle>
                <!-- you can add additional bindings from the layoutitem to the DockWindowVM -->
                <Style TargetType="{x:Type dockctrl:LayoutItem}" >
                    <Setter Property="Title" Value="{Binding Model.Title}" />
                    <Setter Property="IsActive" Value="{Binding Model.IsActive}" />
                    <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}" />
                    <Setter Property="CanClose" Value="{Binding Model.CanClose}" />
                </Style>
            </xcad:DockingManager.LayoutItemContainerStyle>

            <xcad:DockingManager.Resources>
                <!-- add views for specific ViewModels -->
                <DataTemplate DataType="{x:Type diagramsVM:DiagramVM}">
                    <view:Diagram />
                </DataTemplate>
            </xcad:DockingManager.Resources>

            <xcad:LayoutRoot>
                <xcad:LayoutPanel Orientation="Horizontal">
                    <!--Левая колонка-->
                    <xcad:LayoutAnchorablePane DockWidth="240" DockMinWidth="240">
                        <xcad:LayoutAnchorable Title="Компоненты" x:Name="controls">
                            <cc:ControlsPane DataContext="{Binding ControlsVM}" />
                        </xcad:LayoutAnchorable>
                        <xcad:LayoutAnchorable Title="Импортированные графики" x:Name="importedGraphics">
                            <ic:Pane DataContext="{Binding ImportedControlsPaneVM}" />
                        </xcad:LayoutAnchorable>
                    </xcad:LayoutAnchorablePane>
                    <!--Средняя колонка-->
                    <xcad:LayoutPanel Orientation="Vertical">
                        <xcad:LayoutAnchorablePaneGroup DockHeight="70">
                            <xcad:LayoutAnchorablePane>
                                <xcad:LayoutAnchorable  Title="Среднеквадратичные отклонения" x:Name="standardDerivations" IsVisible="False">
                                    <view:StandardDeviations DataContext="{Binding StandardDeviationsGroupVM}" />
                                </xcad:LayoutAnchorable>
                            </xcad:LayoutAnchorablePane>
                        </xcad:LayoutAnchorablePaneGroup>
                        <xcad:LayoutDocumentPane x:Name="documentPane" />
                    </xcad:LayoutPanel>
                    <!--Правая колонка-->
                    <xcad:LayoutAnchorablePane   DockWidth="Auto">
                        <xcad:LayoutAnchorable  Title="Отчет о массах" x:Name="massReport" IsVisible="False">
                            <view:MassReport DataContext="{Binding MassReportVM}" />
                        </xcad:LayoutAnchorable>
                        <xcad:LayoutAnchorable  Title="Вид кривых" x:Name="lineDesigner" IsVisible="False">
                            <view:LineDesigner DataContext="{Binding LineDesignerVM}"/>
                        </xcad:LayoutAnchorable>
                    </xcad:LayoutAnchorablePane>
                </xcad:LayoutPanel>
            </xcad:LayoutRoot>
        </xcad:DockingManager>

    </Grid>
</Window>

Стек-трейс:

System.NullReferenceException
  HResult=0x80004003
  Сообщение = Ссылка на объект не указывает на экземпляр объекта.
  Источник = Xceed.Wpf.AvalonDock
  Трассировка стека:
   в Xceed.Wpf.AvalonDock.Controls.LayoutAnchorableTabItem.OnMouseEnter(MouseEventArgs e)
   в System.Windows.UIElement.OnMouseEnterThunk(Object sender, MouseEventArgs e)
   в System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   в System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   в System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   в System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   в System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   в System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   в System.Windows.MouseOverProperty.FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, Boolean oldValue)
   в System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState, Action`2 originChangedAction)
   в System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState, Action`2 originChangedAction)
   в System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState, Action`2 originChangedAction)
   в System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState, Action`2 originChangedAction)
   в System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState, Action`2 originChangedAction)
   в System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState, Action`2 originChangedAction)
   в System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState, Action`2 originChangedAction)
   в System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState, Action`2 originChangedAction)
   в System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState, Action`2 originChangedAction)
   в System.Windows.ReverseInheritProperty.OnOriginValueChanged(DependencyObject oldOrigin, DependencyObject newOrigin, IList`1 otherOrigins, DeferredElementTreeState& oldTreeState, Action`2 originChangedAction)
   в System.Windows.Input.MouseDevice.ChangeMouseOver(IInputElement mouseOver, Int32 timestamp)
   в System.Windows.Input.MouseDevice.PreNotifyInput(Object sender, NotifyInputEventArgs e)
   в System.Windows.Input.InputManager.ProcessStagingArea()
   в System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   в System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   в System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   в System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   в System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   в MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   в MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   в System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   в System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   в System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   в MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   в MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   в System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   в System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   в System.Windows.Application.RunDispatcher(Object ignore)
   в System.Windows.Application.RunInternal(Window window)
   в System.Windows.Application.Run(Window window)
   в System.Windows.Application.Run()
   в Galaxy_Rotation_4.App.Main()
READ ALSO
Cannot use a lambda expression as an argument в представление razor

Cannot use a lambda expression as an argument в представление razor

В aspnet core передал вот эту модель в view

116
Синхронный метод через асинхронный

Синхронный метод через асинхронный

Многие API предоставляют как синхронные, так и асинхронные методы

110
Как реализовать таймаут на C#?

Как реализовать таймаут на C#?

Доброго времени суток всем читающим!

104
Не работает сравнение объектов по полям C#

Не работает сравнение объектов по полям C#

Есть вот такой код для сравнения двух объектовПроблема в том, что if() с проверками на тип, имя и значение полей работает как-то неадекватно

89