Closing TabbedMdiContainer when no DoucmentWindow is loaded

Docking/MDI for WPF Forum

Posted 16 years ago by uran1
Version: 4.5.0476
Platform: .NET 3.5
Environment: Windows XP (32-bit)
Avatar
Closing TabbedMdiContainer (cross on right top side) when no DocumentWindow is added to Items collection throw exception:

System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  Source="ActiproSoftware.Docking.Wpf30"
  StackTrace:
       at ActiproSoftware.Windows.Controls.Docking.DockHost.OnPreviewGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
       at System.Windows.UIElement.OnPreviewGotKeyboardFocusThunk(Object sender, KeyboardFocusChangedEventArgs e)
       at System.Windows.Input.KeyboardFocusChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
       at System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew)
       at System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
       at System.Windows.UIElement.Focus()
       at ActiproSoftware.Windows.Controls.Docking.DockingWindowContainer.e(Boolean A_0)
       at ActiproSoftware.Windows.Controls.Docking.DockingWindowContainer.OnPreviewMouseDown(MouseButtonEventArgs e)
       at System.Windows.UIElement.OnPreviewMouseDownThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at WpfApplication8.App.Main() in c:\Projects\Temp\WpfApplication8\WpfApplication8\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

Sample application (only XAML in application)

<ribbon:RibbonWindow
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
    xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
    xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
    xmlns:Themes="clr-namespace:ActiproSoftware.Windows.Themes;assembly=ActiproSoftware.Shared.Wpf30"
    xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
    xmlns:Media="clr-namespace:System.Windows.Media;assembly=PresentationCore"
    xmlns:Drawing="clr-namespace:System.Drawing;assembly=System.Drawing"
      x:Class="WpfApplication8.MainWindow"
      ApplicationName="AAA" WindowState="Maximized"  
    Themes:ThemeManager.Theme="Office2007Black"
  
  
  >
    <DockPanel LastChildFill="True" x:Name="MainDockPanel" >
        <ribbon:Ribbon x:Name="ribbon" DockPanel.Dock="Top"  >
            <ribbon:Ribbon.Tabs>
                <ribbon:Tab Label="General">
                    <ribbon:Group Label="Files">
                        <ribbon:Button  Label="Load plugin"/>
                    </ribbon:Group>
                </ribbon:Tab>
            </ribbon:Ribbon.Tabs>
        </ribbon:Ribbon>
        <docking:DockSite x:Name="dockSite" >
            <docking:Workspace>
                <docking:TabbedMdiHost x:Name="tabbedMdiHost">

                    <docking:TabbedMdiContainer  x:Name="tabbedMdiContainer" Background="Gold">
                       
                    </docking:TabbedMdiContainer>
                </docking:TabbedMdiHost>
            </docking:Workspace>
        </docking:DockSite>
    </DockPanel>
</ribbon:RibbonWindow>

Comments (8)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
This is related to you having an empty TabbedMdiContaine there. If no documents are loaded there should be no TabbedMdiContainer in the TabbedMdiHost. The product will automatically add and remove TabbedMdiContainers as needed when documents are activated and closed.

The only time you should define a TabbedMdiContainer in XAML is if it contains one or more documents.


Actipro Software Support

Posted 15 years ago by Aliaksei
Avatar
Hi,

I wonder what kind of objects can be placed in Content property of TabbedMdiHost?
As I found it can be TabbedMdiContainer and split container with collection of TabbedMdiContainers. Something else? I need in progrommatic adding of tabs to its.
And as I understand after closing last document in mdi container - it disappeared. So if I want to open new document in this state I need to create mdi container from code and set it to mdi host content property. Am I right?

Thank you.
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Aliaksei,

Other than the initial XAML setup, you should never modify the Content of a TabbedMdiHost. At run-time the DockSite manages that for you. The set of controls you can place in a TabbedMdiHost in your XAML is indicated in the "Control Hierarchy" documentation topic. Please see that.

At run-time, yes closing the last document removes the MDI container that was there. MDI containers (same with split containers and tool window containers) are dynamically created and destroyed as needed.

To add a new document (we show this in numerous samples), all you do is create a DocumentWindow using a constructor that takes a DockSite, and then call its Activate event. You never need to worry about containers, etc.


Actipro Software Support

Posted 15 years ago by Aliaksei
Avatar
ok and what I need to do to place toolwindow in mdi container if it not exists?
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Set the ToolWindow.State property to DockingWindowState.Document and ensure it is open by calling Open() or Activate().


Actipro Software Support

Posted 15 years ago by Aliaksei
Avatar
ToolWindow.State - no setter property :(
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Whoops, my mistake. Call ToolWindow.MoveToMdi() instead. That sets the State property internally.


Actipro Software Support

Posted 15 years ago by Aliaksei
Avatar
Thank you
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.