How to add a WPF UserControl to the Tab Content

6 posts, 0 answers
  1. hkdave95
    hkdave95 avatar
    245 posts
    Member since:
    Nov 2006

    Posted 19 Oct 2008 Link to this post

    Hi

    I need to add a WPF User control to the tab content programmatically.

    Have you got any examples of this ?

    Kind Regards

    David
  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 21 Oct 2008 Link to this post

    Hello David,

    I answered in this thread as well:

    http://www.telerik.com/community/forums/thread/b311D-bgmgck.aspx

    If you want, you can add the UserControls directly as items of the TabControl, you just need to bind the header of the TabItem to a property that will exist on all UserControls. If we use the example from the thread, the style needs to be slightly modified :

    <nav:RadTabControl x:Name="tabControl">  
        <nav:RadTabControl.ItemContainerStyle> 
            <Style TargetType="nav:RadTabItem">  
                <Setter Property="Header" 
                        Value="{Binding Description}" /> 
                <Setter Property="Conent" 
                        Value="{Binding}" /> 
            </Style> 
        </nav:RadTabControl.ItemContainerStyle> 
    </nav:RadTabControl> 

    I.e. you place the UserControl (the item) as content of the TabItem, while one of its properties (Description) is bound to the header.

    Hopefully this will help you in your case.

    Kind regards,
    Miroslav
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WPF is Visual Studio 2017 Ready
  4. hkdave95
    hkdave95 avatar
    245 posts
    Member since:
    Nov 2006

    Posted 30 Oct 2008 Link to this post

    Hi

    Sorry to be a nuisance, but do you have a programmatic example ?

    Kind Regards

    David
  5. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 25 Nov 2008 Link to this post

    Hi David,

    Sorry for the delayed reply,

    You can programmatically add TabItems like so:

    var tabItem = new RadTabItem();  
    tabItem.Header = "My Tab Header";  
    tabItem.Content = new MyUserControl();  
    tabControl.Items.Add(tabItem); 

    The first example also adds items programmatically, but uses the ItemsSource rather than directly creating and adding the items.

    I hope this is what you need,

    Regards,
    Miroslav
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Allen
    Allen avatar
    50 posts
    Member since:
    Mar 2011

    Posted 21 Feb 2012 Link to this post

    Can you also style this user control with a Telerik theme at the same time? 
    My usercontrols have a mixture of Windows and Telerik controls, but when I set them into the tab control like this, they only have the startup style and cannot be restyled dynamically.  The rest of the controls do respond to dynamic style change.
    Any ideas?
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 24 Feb 2012 Link to this post

    Hi Allen ,

     Since this is a very old post, could you please elaborate more on your scenario? What is your RadControls version? What are the controls that you use in the TabItems' Content? What do you mean by "the  rest of the controls"? Is it possible for you to send us an isolated sample showing your issues? 
    Please note that dynamic style/theme/template change is usually considered as bad practice that may lead to various issues. 

    All the best,
    Petar Mladenov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
UI for WPF is Visual Studio 2017 Ready