C1DockGroup throws Invalid Child exception when binding ItemsSource

Posted by: vinothkumar.r2210 on 7 October 2020, 1:29 am EST

  • Posted 7 October 2020, 1:29 am EST

    Hi,
    I am binding my class object as ItemsSource to C1DockGroup controls. It throws error immediately after adding one new item in collection. Please find the below xaml code and class object.

    XAML Code:

    <c1:C1TabControl x:Name="TabControl" Grid.Column="1" ItemsSource="{Binding TabVisualizers}" TabItemClose="InEachTab"
    SelectedItem="{Binding SelectedVisualizerTab,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" AllowDrop="True">
    <c1:C1TabControl.ItemTemplate>
    <DataTemplate>
    <TextBlock Text="{Binding TabName,UpdateSourceTrigger=PropertyChanged}"></TextBlock>
    </DataTemplate>
    </c1:C1TabControl.ItemTemplate>
    <c1:C1TabControl.ContentTemplate>
    <DataTemplate>
    <Grid>
    <c1:C1DockControl x:Name="dockControl" Grid.Row="2" AllowDrop="True" Drop="DropList_Drop" ItemDockModeChanged="DockControl_ItemDockModeChanged" PickerLoading="DockControl_PickerLoading">
    <c1:C1DockGroup ItemsSource="{Binding TabContents,UpdateSourceTrigger=PropertyChanged}">
    <!--<c1:C1DockGroup.ItemContainerStyle>
    <Style TargetType="{x:Type c1:C1DockGroup}">
    <Setter Property="ItemTemplate">
    <Setter.Value>
    <DataTemplate>
    <dockControl:DockTabControl DockMode="{Binding DockMode,UpdateSourceTrigger=PropertyChanged}" Drop="DropList_Drop" FilterCommand="{Binding FilterCommand,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}" MaximizeCommand="{Binding MaximizeCommand,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}">
    <c1:C1DockTabItem Header="{Binding TableName,UpdateSourceTrigger=PropertyChanged}">

    </c1:C1DockTabItem>
    </dockControl:DockTabControl>
    </DataTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    </c1:C1DockGroup.ItemContainerStyle>-->
    <c1:C1DockGroup.ItemTemplate>
    <DataTemplate>
    <dockControl:DockTabControl DockMode="{Binding DockMode,UpdateSourceTrigger=PropertyChanged}" Drop="DropList_Drop" FilterCommand="{Binding FilterCommand,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}" MaximizeCommand="{Binding MaximizeCommand,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}">
    <c1:C1DockTabItem Header="{Binding TableName,UpdateSourceTrigger=PropertyChanged}">

    </c1:C1DockTabItem>
    </dockControl:DockTabControl>
    </DataTemplate>
    </c1:C1DockGroup.ItemTemplate>
    </c1:C1DockGroup>
    </c1:C1DockControl>
    </Grid>
    </DataTemplate>
    </c1:C1TabControl.ContentTemplate>
    </c1:C1TabControl>

    Class Object:

    public class TabVisualizer
    {
    private string _tabName;
    private ObservableCollection<TabContent> tabContents;

    public string TabName { get => _tabName; set => _tabName = value; }

    public ObservableCollection<TabContent> TabContents
    {
    get
    {
    return tabContents;
    }
    }

    public TabVisualizer()
    {
    tabContents = new ObservableCollection<TabContent>();
    }
    }

    public class TabContent : ViewModelBase
    {
    private string _tableName;
    private string _fullName;
    private C1.WPF.Docking.DockMode _dockMode;
    private object _dockTabContent;
    public string TableName { get => _tableName; set => _tableName = value; }
    public string FullName { get => _fullName; set => _fullName = value; }
    public DockMode DockMode { get => _dockMode; set { _dockMode = value; RaisePropertyChanged(); } }

    public object DockTabContent { get => _dockTabContent; set { _dockTabContent = value; RaisePropertyChanged(); } }
    }

    Logic:

    private void AddNewTabItem()
    {
    var tabVisualizer = new TabVisualizer() { TabName = $"Header {TabControl.Items.Count + 1}" };
    TabVisualizers.Add(tabVisualizer);
    TabControl.SelectedIndex = TabControl.Items.Count - 1;
    }
    private ObservableCollection<TabVisualizer> _tabs;
    public ObservableCollection<TabVisualizer> TabVisualizers { get => _tabs; }
    private TabVisualizer selectedVisualizerTab;
    public TabVisualizer SelectedVisualizerTab { get => selectedVisualizerTab; set { selectedVisualizerTab = value; RaisePropertyChanged(); } }
    private void AddContents()
    {
    TabContent tabContent = new TabContent();
    tabContent.DockMode = DockMode.Docked;
    tabContent.FullName = nodeResult.NodeName;
    tabContent.TableName = nodeResult.NodeName;
    SelectedVisualizerTab.TabContents.Add(tabContent);
    }

    Thanks and Regards,
    Vinoth Kumar Ravi
  • Marked as Answer

    Replied 7 October 2020, 10:08 pm EST

    Hi Vinoth,

    It seems like you have created a duplicate post for the same query. So, we have replied to your original post https://www.grapecity.com/forums/wpf-edition/problem-with-c1dockgroup-a.

    And please try to avoid creating multiple posts for the same query because it may lead to confusion.

    Regards,
    Kartik.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels