This is a migrated thread and some comments may be shown as answers.

Displaying Close Button On Tabs

5 Answers 157 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Brian Mains
Top achievements
Rank 1
Brian Mains asked on 04 Jan 2010, 02:12 AM
Hello,

I want the users to be able to invoke a close on the tabs in my tab control, like Visual Studio's implementation.  Is that possible in your tab control for WPF?  Didn't see that demo'd anywhere...

Thanks.

5 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 04 Jan 2010, 08:37 AM
Hello Brian Mains,

check this help article:
http://www.telerik.com/help/silverlight/radtabcontrol-how-to-add-close-button-to-the-tab-headers.html

All the best,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Tony Mocella
Top achievements
Rank 1
answered on 05 Mar 2010, 03:00 PM
The article got me most of the way there, but I was wondering how I can bind the tab-header text to the Header property of the basic tab-item.  My HeaderTemplate has a line like this - in place of the ContentControl in the article:
<ContentPresenter x:Name="Content" Grid.Column="0" ContentSource="Header" /> 

When I run my app, I get an error stating that ContentPresenter doesn't have a Header property.  Using the built-in WPF tabcontrol, I was able to do the above and it worked, but using the RadTabControl, I'm getting this error.

Also note, I'm manually adding tab-items to the control at run-time, not doing the ItemsSource approach taken in the article. 
0
Miroslav
Telerik team
answered on 10 Mar 2010, 10:01 AM
Hi Tony Mocella,

Creating the tabs in code should make no difference to the solution.

What do you assign to your headers? If it is a string then you can add a content presenter bound to it like so:

<ContentPresenter Content="{Binding}" />

Adding a ContentSource tries to connect the presenter's properties to its TemplatedParent which is indeed the ContentPresenter in the ControlTemplate of the TabItem.

My guess is that this works in the built-in tab because you are editing its ControlTemplate.

Greetings,
Miroslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Tony Mocella
Top achievements
Rank 1
answered on 10 Mar 2010, 03:59 PM
Great, that gets me most of the way there.  However, I'm not unable to locate controls in my header that I was once locating via base.GetTemplateChild() - I end up with null objects now. 

In an attempt to work around this, I tried to bind some properties of my header-controls to my closeable-tab class (HeaderDirtyFlagVisibility is defaulted to collapsed, but the label is visible at tab-creation and then after)e.g.
private Visibility _headerDirtyFlagVisibility; 
        public Visibility HeaderDirtyFlagVisibility 
        { 
            set 
            { 
                _headerDirtyFlagVisibility = value
                OnPropertyChanged("HeaderDirtyFlagVisibility"); 
            } 
            get 
            { 
                return _headerDirtyFlagVisibility;    
            } 
        } 

and in my Xaml:
 <Setter Property="HeaderTemplate"
      <Setter.Value> 
        <DataTemplate> 
          <Grid> 
            <Grid.ColumnDefinitions> 
              <ColumnDefinition Width="*"/> 
              <ColumnDefinition Width="Auto"/> 
              <ColumnDefinition Width="Auto"/> 
            </Grid.ColumnDefinitions> 
            <ContentPresenter Content="{Binding}" RecognizesAccessKey="True" HorizontalAlignment="Center" VerticalAlignment="Center" ToolTip="{Binding Path=HeaderToolTip, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> 
            <Label x:Name="PART_DirtyLabel" Visibility="{Binding Path=HeaderDirtyFlagVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" Margin="1,0,1,0" VerticalAlignment="Center" ToolTip="Unsaved Changes" 
                  Grid.Column="1" FontWeight="UltraBold" Content="!" Foreground="Black" Background="{DynamicResource DirtyTabWarningBackground}" /> 
            <Button x:Name="PART_Close" Content="x" Width="18" Height="18" HorizontalAlignment="Center" Margin="3,0,0,0" ToolTip="Close Tab" 
                    Grid.Column="2" VerticalAlignment="Center" Controls:CloseableTabItem.EnableRoutedClick="True" /> 
          </Grid> 
        </DataTemplate> 
      </Setter.Value> 
    </Setter>     

0
Miro Miroslavov
Telerik team
answered on 12 Mar 2010, 12:12 PM
Hello Tony Mocella,

You can not locate the label and close button via GetTemplatedChild because they "live" in the HeaderTemplate which is DataTemplate, not the ControlTemplate. Can you give us snipped of what you set for the Header Property? The Header should be an object that has HeaderDirtyFlagVisibility property. And also ContentPresenter i guess have to be bound to some more specific property of that object e.g Title.
Hope this will help you.

Regards,
Miro Miroslavov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
TabControl
Asked by
Brian Mains
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Tony Mocella
Top achievements
Rank 1
Miroslav
Telerik team
Miro Miroslavov
Telerik team
Share this question
or