ButchersBoy / Dragablz

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

When I drag the tab, I got exception #107

Closed HardySoftware closed 8 years ago

HardySoftware commented 8 years ago

System.Reflection.TargetInvocationException was unhandled HResult=-2146232828 Message=Exception has been thrown by the target of an invocation. Source=mscorlib StackTrace: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Delegate.DynamicInvokeImpl(Object[] args) at System.Windows.RoutedEventArgs.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 e) at Dragablz.DragablzItem.ThumbOnDragDelta(Object sender, DragDeltaEventArgs dragDeltaEventArgs) in C:\projects\dragablz\Dragablz\DragablzItem.cs:line 547 at System.Windows.Controls.Primitives.DragDeltaEventArgs.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 e) at System.Windows.Controls.Primitives.Thumb.OnMouseMove(MouseEventArgs e) at System.Windows.UIElement.OnMouseMoveThunk(Object sender, MouseEventArgs e) at System.Windows.Input.MouseEventArgs.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.RaiseTrustedEvent(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, WindowMessage 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, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) 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.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at GpasThickClient.App.Main() in C:\Projects\Prototypes\App.xaml.cs:line 15 at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: HResult=-2146233069 Message=No parameterless constructor defined for this object. Source=mscorlib StackTrace: at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at Dragablz.DefaultInterTabClient.GetNewHost(IInterTabClient interTabClient, Object partition, TabablzControl source) in C:\projects\dragablz\Dragablz\DefaultInterTabClient.cs:line 14 at Dragablz.TabablzControl.MonitorBreach(DragablzDragDeltaEventArgs e) in C:\projects\dragablz\Dragablz\TabablzControl.cs:line 1170 at Dragablz.TabablzControl.ItemDragDelta(Object sender, DragablzDragDeltaEventArgs e) in C:\projects\dragablz\Dragablz\TabablzControl.cs:line 1087 InnerException:

I have referenced following nuget packages

<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="CommonServiceLocator" version="1.3" targetFramework="net461" />
  <package id="Dragablz" version="0.0.3.163" targetFramework="net461" />
  <package id="Prism.Core" version="6.1.0" targetFramework="net461" />
  <package id="Prism.Unity" version="6.1.1" targetFramework="net461" />
  <package id="Prism.Wpf" version="6.1.0" targetFramework="net461" />
  <package id="Unity" version="4.0.1" targetFramework="net461" />
</packages>

My XAML definition

<Window x:Class="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:ThickClient"
        xmlns:preview="clr-namespace:ThickClient.Regions"
        mc:Ignorable="d"
        xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz"
        xmlns:dockablz="http://dragablz.net/winfx/xaml/dockablz"
        xmlns:prism="http://prismlibrary.com/"
        Closed="MainWindow_OnClosed"
        Activated="MainWindow_OnActivated"
        Title="GPAS Admin">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/Generic.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <ContentControl prism:RegionManager.RegionName="MenuRegion"
                            VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"/>
        <dockablz:Layout Grid.Row="1">
            <dragablz:TabablzControl Name="TabablzControl" ShowDefaultCloseButton="True"
                                     ItemContainerStyle="{StaticResource TrapezoidDragableTabItemStyle}"
                                     AdjacentHeaderItemOffset="-10" Margin="0,4,0,0">
                <dragablz:TabablzControl.ContentTemplate>
                    <DataTemplate DataType="{x:Type preview:DragablzTabClientProxy}">
                        <ContentPresenter Margin="4" Content="{Binding Content}" />
                    </DataTemplate>
                </dragablz:TabablzControl.ContentTemplate>
                <dragablz:TabablzControl.CustomHeaderItemTemplate>
                    <DataTemplate DataType="{x:Type preview:DragablzTabClientProxy}">
                        <TextBlock Text="{Binding CommonData.Title}" MaxWidth="100" TextTrimming="CharacterEllipsis" ToolTip="{Binding CommonData.Title}" />
                    </DataTemplate>
                </dragablz:TabablzControl.CustomHeaderItemTemplate>
                <dragablz:TabablzControl.InterTabController>
                    <dragablz:InterTabController InterTabClient="{Binding InterTabClient}" />
                </dragablz:TabablzControl.InterTabController>
            </dragablz:TabablzControl>
        </dockablz:Layout>
    </Grid>
</Window>
ButchersBoy commented 8 years ago

Hi, can you please post a sample repo with the PRISM stuff set up where this happens please.

HardySoftware commented 8 years ago

I attached my solution here, there are 2 buttons to open 2 tabs. But when I try to drag any of the tab I got the error above.

POC.zip

ButchersBoy commented 8 years ago

"No parameterless constructor defined for this object."

You problem is that MainWindow has a constructor argument. By default, Dragablz is trying to create a new MainWindow, but it relies on a default constructor.

No problem though, you can create a custom IInterTabClient and manage the construction yourself. Check the various samples to see this.

HardySoftware commented 8 years ago

I see what you are talking here. Let's say I still prefer MainWindow to keep current constructor, as you suggested I should implement a class to implement IInterTabClient interface. For now I have service locator to instantiate MainWindow, probably it is where the problem comes from.

The question is how is the class implementing IInterTabClient interface initialized? Who/when the class in initialized? I just try to see if it can wire up with my IOC container.

ButchersBoy commented 8 years ago

Please check samples.

e.g.

https://github.com/ButchersBoy/Dragablz/blob/master/DragablzDemo/BoundExampleWindow.xaml#L68