ButchersBoy / Dragablz

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

Infinite windows appearing when using InterTabController #223

Open Renaudyes opened 5 years ago

Renaudyes commented 5 years ago

When binding the ItemsSource of a dragablz:TabablzControl control an infinite number of windows are appearing while dragging the tabItem.

A repo to demonstrate the problem is available here : https://github.com/Renaudyes/dragablzBug

slow-down commented 5 years ago

that's because you have a startup tab in the mainwindow. it will always get a new window when moving the tab. quick fix is to set a bool firstLaunch to true and check if its true, if its true then add the startup tab. after adding the tab just set it to false. this way it doesn't open anymore. still seems like a bug. this project seems dead, sadly

sebastianraese commented 5 years ago

Hey, after getting almost crazy, I found this thread. It seems, I have the same issue, not able to solve it myself (sorry, I am new to Dragablz).

@slow-down: Can you please explain the solution a bit more in detail? I started with an empty WPF Project, binding a set of view model instances to the dragablz:TabablzControl 'ItemsSource' property. I did not set any startup tap:

<Window x:Class="Views.MainView"
        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:localVMs="clr-namespace:Dragablz.Test.ViewModels"

        xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz"
        xmlns:dockablz="clr-namespace:Dragablz.Dockablz;assembly=Dragablz"

        mc:Ignorable="d"
        Title="MainView" Height="450" Width="800">

    <Window.DataContext>
        <localVMs:MainVM />
    </Window.DataContext>

    <Grid Margin="5">

        <dockablz:Layout Partition="ABC">

            <dragablz:TabablzControl Margin="8" ConsolidateOrphanedItems="True" x:Name="InitialTabablzControl" ItemsSource="{Binding Children}">

                <dragablz:TabablzControl.InterTabController>
                    <dragablz:InterTabController Partition="ABC" />
                </dragablz:TabablzControl.InterTabController>

                <dragablz:TabablzControl.ContentTemplate>
                    <DataTemplate>
                        <ContentPresenter Content="{Binding View}" />
                    </DataTemplate>
                </dragablz:TabablzControl.ContentTemplate>

                <!--
                <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>
                -->

            </dragablz:TabablzControl>

        </dockablz:Layout>

    </Grid>

</Window>

Thanks a lot!

slow-down commented 5 years ago

@blogathauptstadtbytes I guess it's because of the binding ItemsSource="{Binding Children}" but I'm not sure. If you run your app, you should not see any tabs. If you do then thats your problem. When you drag a tab out of the window it creates a new instance of itselfe -> the mainwindow. so it also inserts the default tabs. you have to check in the codebehind if its the first instance or not. only show the "default" / "startup" tabs on the first run. you could set a bool or counter or whatever you like.

there is probably a better solution to this but i didnt find any better way of solving this. If you still dont understand what i mean then please send me some screenshots of how the tabs look at startup and how it looks after you drag one tab out to create a new window.

sebastianraese commented 5 years ago

Hi, thanks for your response.

Since my application is WPF/MVVM-based, I expected to see tabs when binding the 'ItemsSource' property to an "ObservableCollection(of ViewModel)" (=Children) since this is the way it's done. I did not expect the manager to create no instances of the 'MainWindow" (I have to manage myself).

Bild1

slow-down commented 5 years ago

since im just starting out with wpf and mvvm i can't help you with the binding stuff. But your screenshots show exactly what i mentioned. maybe there is a property in dragablz/tabbablz which will only instantiate the window and the tabs once. but now you know what the problem is, maybe you can find out how to fix it. let me know if you found something useful so other people, including me, can also use it properly.

DirkImWiderstand commented 4 years ago

Hey there! I run in exactly the same issue. But strangely it happened since I made an InterTabClient and bound it to the dragablz:TabablzControl.InterTabController. Before that, I was able to drag the tabs out of the control, but the dragged out tabs lost the ViewModel. I am not generating tabs by binding the items Property to the ViewModel, there are always three fixed TabItems. So I don't think you have a binding problem here. Does anyone have a clue what is happening here?

Renaudyes commented 4 years ago

Hey !

Actually they are pending pull requests. In those requests you have some changes that fix the bug. I have found a library that has everything implemented here : https://github.com/speedyalibaba/Savablz

Hope this help

DirkImWiderstand commented 4 years ago

Great, thank you! I stumbled over this repo as well. I will give it a try tomorrow

sebastianraese commented 4 years ago

Hi folks,

I tested Savablz (just replacing the Dragablz nuget package by the Savablz package) and it works as expected. Thanks a lot for the hint!