Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:54:30+00:00 2026-06-07T23:54:30+00:00

In my view i’m adding dynamically custom TabItems (TextseiteTabItem). With the property DataContext i

  • 0

In my view i’m adding dynamically custom TabItems (TextseiteTabItem). With the property DataContext i gave each TabItem a Model to work with (fill in values). Now i added a close-command to the custom TabItems but it wont work. I cant manage to send the close-command to the viewmodel. Above is my attempt..

My custom TabItem:

<sdk:TabItem x:Class="PortfolioCreator.TextseiteTabItem" 
           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"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">

    <sdk:TabItem.Header>
        <StackPanel Orientation="Horizontal">
            <sdk:Label Content="{Binding Seitennummer, StringFormat='Seite {0}', Mode=TwoWay}"/>
            <Button Content="X"
                    Command="{Binding CloseTabCommand, Mode=TwoWay}"
                    DataContext="{Binding ElementName=TemplateTabControl}"
                    CommandParameter="{Binding SelectedItem, ElementName=TemplateTabControl}" />   
        </StackPanel>
    </sdk:TabItem.Header>

    <sdk:TabItem.Content>
        <Grid x:Name="LayoutRoot">
            ...
        </Grid>
    </sdk:TabItem.Content>
</sdk:TabItem>

In my View:

...
<sdk:TabControl toolkit:DockPanel.Dock="Bottom" ItemsSource="{Binding Tabs}" x:Name="TemplateTabControl"/>
...

In my ViewModel:

public class PortfolioViewModel : ViewModelBase
{
    public ObservableCollection<TabItem> Tabs { get; set; }

    public RelayCommand<TabItem> CloseTabCommand
    {
        get;
        private set;
    }

    public PortfolioViewModel()
    {
        CloseTabCommand = new RelayCommand<TabItem>(tab =>
        {
            //never reached
        },
        tab =>
        {
            //never reached
        });

        Tabs = new ObservableCollection<TabItem>();

        AddTextseite();
        AddTextseite();          
    }

    void AddTextseite()
    {
        TabItem item = new TextseiteTabItem();
        item.DataContext = new TextSeiteModel();

        Tabs.Add(item);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:54:32+00:00Added an answer on June 7, 2026 at 11:54 pm

    This is my workaround for this problem. I admit it is not a good solution and breaks the mvvm pattern but as @herzmeister says other approaches are too elaborate for my project right now. (But it won’t be the final solution 😉 )

    TabItemViewModel:

    public delegate void CloseTabItemHandler();
    
    public class TextseiteTabItemViewModel : ViewModelBase
    {
        public event CloseTabItemHandler CloseTabItem;
        public RelayCommand CloseTabCommand {get; set;}
    
        public TextseiteTabItemViewModel()
        {
            CloseTabCommand = new RelayCommand(() =>
            {
                if (CloseTabItem == null) return;
                CloseTabItem();
            });
        }
    }
    

    TabItemView:

    <sdk:TabItem x:Class="PortfolioCreator.TextseiteTabItemView" 
            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"
            mc:Ignorable="d"
            xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
            xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
            xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
    
        <sdk:TabItem.Header>
            <StackPanel Orientation="Horizontal">
                <Button Content="X" Command="{Binding CloseTabCommand, Mode=TwoWay}" />  
            </StackPanel>
        </sdk:TabItem.Header>
    
        <sdk:TabItem.Content>
            <Grid x:Name="LayoutRoot">
                ...
            </Grid>
        </sdk:TabItem.Content>
    </sdk:TabItem>
    

    Parent ViewModel:

    public class PortfolioViewModel : ViewModelBase
    {
        public ObservableCollection<TabItem> Tabs { get; set; }
    
        public PortfolioViewModel()
        {
            Tabs = new ObservableCollection<TabItem>();
    
            AddTextseite();
            AddTextseite();
        }
    
        void AddTextseite()
        {
            var viewmodel = new TextseiteTabItemViewModel();
    
            TabItem item = new TextseiteTabItemView();
            item.DataContext = viewmodel;
    
            viewmodel.CloseTabItem += new CloseTabItemHandler(() => 
            { 
                Tabs.Remove(item);
            });
    
            Tabs.Add(item);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The View controller programming guide states this regarding view controller's usage: Each custom view
My view model has the property: public IEnumerable<string> Names { get; set; } My
By 'view' here I mean different combinations of properties of the model, not the
My view page has a Model which is represented by a List of Students.
custom view: public class MyView extends AbstractView { .... awesome stuff ... } controller:
view: <% @post.comments.each do |comment| %> <p> <b>Comment:</b> <%= comment.content %> </p> <p> <b>Commenter</b>
My view: <div class=editor-label> @Html.LabelFor(model => model.UserList) </div> <div class=editor-field> @Html.ListBoxFor(model => model.SelectedUsers, new
My View is bound to a Model and displays several dropdown lists, and their
New view based project in XCode Go to main.xib and view.xib respectively In each
`//View <tr><td>Experience level</td><td><div class=editor-field> <%: Html.DropDownListFor(model => model.ExperienceLevelID, (SelectList)ViewData[Experience], --select--)%> <%: Html.ValidationMessageFor(model => model.ExperienceLevelID)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.