Click here to Skip to main content
15,897,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Heys, I currently have a set up that allows me to add and remove new tabs, the only problem is I have problem adding anything to this new tab. I want to have a text box in there but am having troubling adding one, the tabs are just appearing as blank. Any help would be great, thank you!

Here is how I have it setup:

The button that makes a new tab:

HTML
<Button
                               FontSize="12"
                               Content="Private Chat"
                               Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="147,118,0,0" VerticalAlignment="Top" Width="75"
                               Name="btnPrivateChat" Click="btnPrivateChat_Click" />



Which calls this function:

C#
private void btnPrivateChat_Click(object sender, RoutedEventArgs e)
       {

           ListBoxItem userName = lstOnlineUsers.SelectedItem as ListBoxItem;

           if (userName != null)
           {
               TabHandler newTabItem = new TabHandler();
               newTabItem.Title = userName.Content.ToString();
               ;
               ChatTabControl.Items.Add(newTabItem);
               newTabItem.Focus();
               newTabItem.ApplyTemplate();
           }
           else
           {

               MessageBox.Show("Error! Please select a username.");
           }
       }


Which then creates an instance of the usercontrol TabHandler:

C#
public TabHandler()
{
    // Create an instance of the usercontrol
    TabHeader tabHeader = new TabHeader();







Usercontrol TabHandler (XAML) :

HTML
<usercontrol x:class="TrapezoidTabs.TabHeader" xmlns:x="#unknown">
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="23" d:DesignWidth="81" Margin="0">
    <grid>
        <Button Content="X"  Height="19" HorizontalAlignment="Right" Margin="0,3,4,0" Name="btnCloseTab" VerticalAlignment="Top" Width="20" FontFamily="Courier" FontWeight="Bold" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" FontStretch="Normal" Visibility="Visible" FontSize="14" Padding="0" ToolTip="Close"/>
        <Label FontSize="14" Foreground="Black" Content="User"  Height="23" HorizontalAlignment="Left" Margin="4,1,0,0" Name="lblTabTitle" VerticalAlignment="Top" />
    </grid>
</usercontrol>






Should I be making a new Window instead of a usercontrol? I realy want to add content to each page. Thanks in advance!
Posted
Updated 29-Sep-11 18:27pm
v2

Try the Content property of your TabItem.

newTabItem.Content = [Your Textbox]
 
Share this answer
 
I am little confused by what you are doing but I have a suggestion.

Rather than adding to the TabControl you can bind the ItemSource to a collection inside the DataContext. If the collection is an ObservableCollection it will update for you.

Next, the collection can hold data context for other user controls. You then set the data template for that datacontext

e.g.
XAML
<datatemplate datatype="{x:Type viewModels:YourDataContextObject}">
   <view:yourviewcontrol xmlns:view="#unknown" />
</datatemplate>


Please disreguard the xmlns:view="#unknown". Some formatting issues.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900