ButchersBoy / Dragablz

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

Throws System.Reflection.TargetInvocationException while dragging a tab when the tabs are created using ItemsSource. #276

Open nima-ghomri opened 1 year ago

nima-ghomri commented 1 year ago

I have a .NET 7 WPF project where I defined a view and a view model as below:

MainWindow.xaml

<Window x:Class="DragablzExamples.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:dragablz="http://dragablz.net/winfx/xaml/dragablz"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DragablzExamples"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance Type=local:MainWindowViewModel}"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <dragablz:TabablzControl ItemsSource="{Binding Items}" Margin="8">
            <dragablz:TabablzControl.InterTabController>
                <dragablz:InterTabController/>
            </dragablz:TabablzControl.InterTabController>
        </dragablz:TabablzControl>
    </Grid>
</Window>

MainWindow.xaml.cs

using System.Windows;

namespace DragablzExamples
{
    public class MainWindowViewModel
    {
        public string[] Items { get; set; } = new[] { "Item #1", "Item #2", "Item #3" };
    }
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            DataContext = new MainWindowViewModel();
            InitializeComponent();
        }
    }
}

When I try to drag a tab I get the System.Reflection.TargetInvocationException. It works perfectly when I add TabItems to the main container manually but it throws exception when I use binding. what is wrong with this simple view?