Displaying Close Button On Tabs

6 posts, 0 answers
  1. Brian Mains
    Brian Mains avatar
    485 posts
    Member since:
    Oct 2008

    Posted 03 Jan 2010 Link to this post

    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.
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 04 Jan 2010 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Tony Mocella
    Tony Mocella avatar
    9 posts
    Member since:
    Jan 2010

    Posted 05 Mar 2010 Link to this post

    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. 
  5. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 10 Mar 2010 Link to this post

    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.
  6. Tony Mocella
    Tony Mocella avatar
    9 posts
    Member since:
    Jan 2010

    Posted 10 Mar 2010 Link to this post

    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>     

  7. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 12 Mar 2010 Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready