ButchersBoy / Dragablz

Dragable and tearable tab control for WPF
http://dragablz.net
MIT License
2.17k stars 320 forks source link

Exception when dragging a tab out. #235

Open DouglasLSilva opened 4 years ago

DouglasLSilva commented 4 years ago

I Create a new WPF Application with Unity IOC and when a drag the tabs out, occurs a exception.

Here's the StackTrace

System.Reflection.TargetInvocationException
  HResult=0x80131604
  Message= An exception was thrown by the destination of a call.
  Source=mscorlib
  StackTrace:
   on System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   on System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   on System.Delegate.DynamicInvokeImpl(Object[] args)
   on System.Windows.RoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   on System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   on System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   on System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   on System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   on System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   on Dragablz.DragablzItem.ThumbOnDragDelta(Object sender, DragDeltaEventArgs dragDeltaEventArgs)
   on System.Windows.Controls.Primitives.DragDeltaEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   on System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   on System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   on System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   on System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   on System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   on System.Windows.Controls.Primitives.Thumb.OnMouseMove(MouseEventArgs e)
   on System.Windows.UIElement.OnMouseMoveThunk(Object sender, MouseEventArgs e)
   on System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   on System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   on System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   on System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   on System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   on System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   on System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   on System.Windows.Input.InputManager.ProcessStagingArea()
   on System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   on System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   on System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   on System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   on System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   on MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   on MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   on System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   on System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   on System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   on MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   on MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   on System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   on System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   on System.Windows.Application.RunDispatcher(Object ignore)
   on System.Windows.Application.RunInternal(Window window)
   on System.Windows.Application.Run(Window window)
   on System.Windows.Application.Run()
   on WPF.NoPrism.App.Main()

Inner Exception 1:
MissingMethodException: No constructor without parameters has been defined for this object.

And this is the XAML:

<Window x:Class="WPF.NoPrism.MainWindow"
        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:local="clr-namespace:WPF.Client.NoPrism"
        xmlns:UserControlsHeader="clr-namespace:WPF.NoPrism.Views.UserControls.Headers"
        xmlns:UserControlsSidebar="clr-namespace:WPF.NoPrism.Views.UserControls.Sidebar"
        xmlns:UserControlMainContent="clr-namespace:WPF.NoPrism.Views.UserControls.Main" xmlns:dockablz="http://dragablz.net/winfx/xaml/dockablz" xmlns:dragablz="http://dragablz.net/winfx/xaml/dragablz"
        mc:Ignorable="d"
        Title="{Binding Title}" Height="600" Width="800" MinWidth="750"
        Background="{DynamicResource MaterialDesignPaper}"
        WindowState="Maximized">
    <Grid>
        <UserControlsHeader:Header DataContext="{Binding HeaderViewModel}"  Height="120" VerticalAlignment="Top"/>
        <UserControlsSidebar:Sidebar DataContext="{Binding SidebarViewModel}"  Margin="0,125,0,30" HorizontalAlignment="Left" Width="120" />
        <Grid Margin="120,125,0,25">
            <dockablz:Layout Partition="Main">
                <dragablz:TabablzControl Margin="8" ConsolidateOrphanedItems="True">
                    <dragablz:TabablzControl.InterTabController>
                        <dragablz:InterTabController Partition="Main" />
                    </dragablz:TabablzControl.InterTabController>
                    <TabItem Header="Tab No. 1" IsSelected="True">
                        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">Hello World</TextBlock>
                    </TabItem>
                    <TabItem Header="Tab No. 2">
                        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">We Have Tearable Tabs!</TextBlock>
                    </TabItem>
                    <TabItem Header="Tab No. 3">
                        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">We Have Tearable Tabs!</TextBlock>
                    </TabItem>
                </dragablz:TabablzControl>
            </dockablz:Layout>
        </Grid>
    </Grid>
</Window>

I don`t know what to do to correct this error, pls help ")

DouglasLSilva commented 4 years ago

I solved the problem by creating an empty constructor in MainWindow.

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        public MainWindow(IUnityContainer container)
        {
            DataContext = container.Resolve<IMainWindowViewModel>();
            InitializeComponent();
        }
    }

But i wanna know if is possible to use Tabs on a User Control ? Because in the first time a was using the tabs on a UserControl

codingdna2 commented 4 years ago

I think you should implement InterTabClient. In this way you can control creation of MainWindow instance.

Here's mine:

    public class InterTabClient : IInterTabClient
    {
        public INewTabHost<Window> GetNewHost(IInterTabClient interTabClient, object partition, TabablzControl source)
        {
            var view = ServiceLocator.Current.GetInstance<MainWindow>();

            return new NewTabHost<Window>(view, view.Tabs);
        }

        public TabEmptiedResponse TabEmptiedHandler(TabablzControl tabControl, Window window)
        {
            return TabEmptiedResponse.CloseWindowOrLayoutBranch;
        }
    }

In MainWindow:

            <dragablz:TabablzControl.InterTabController>
                <dragablz:InterTabController InterTabClient="{Binding InterTabClient}" />
            </dragablz:TabablzControl.InterTabController>

In MainViewWindowModel: public IInterTabClient InterTabClient { get; } = new InterTabClient();