• A new Silverlight control - TabControl


    Silverlight 2 brings a suite of controls for designers and developers to leverage within their applications.  With the Expression tools helping us to be able to skin these controls, also comes some new controls you may not have used yet as well as a new one introduced with the latest release of Silverlight 2.

    Introducing TabControl.

    UPDATE: Video walk-through is now live.

    The TabControl is implemented in the System.Windows.Controls.Extended class library and not in the Silverlight core.  To use it make a reference to the Extended assembly and it will be available to you.  In Expression Blend you’ll see TabControl in the Custom Controls section of the Asset Library:

    You’ll notice there is actually a TabControl and TabItem controls…to implement you’ll need them both.  In Blend, you’ll have to drag a TabControl onto the design surface.  Once you have it, double-click on the TabControl in the Objects and Timeline explorer so that it has a yellow ring around it:

    Having the yellow border indicates that it is the actively selected element.  Now if you go back to the asset library, change to a TabItem and double-click the TabItem, it will be added as a child of the TabControl.  Do this several times to add as many TabItems you need:

    The resulting XAML looks like this:

    <ex:TabControl TabStripPlacement="Bottom" VerticalAlignment="Top" 
                   Width="231.148" Height="156.611" HorizontalAlignment="Left" 
                   x:Name="tabstrip1">
        <ex:TabItem Width="75" Height="20">
        </ex:TabItem>
        <ex:TabItem Width="75" Height="20" Header="Second">
        </ex:TabItem>
        <ex:TabItem Width="75" Height="20" Header="Third">
        </ex:TabItem>
    </ex:TabControl>

    You’ll notice the “ex” namespace with the TabControl.  Yours may be different and likely “System_Windows_Controls“ if you followed the steps above.  This is added automatically when you drag a control onto the surface from the asset library.  The namespace is actually directed in the root node of the XAML and you can change it to whatever you’d like.

    The TabControl has properties you can set on it just like any other control, but one that you might find important would be the TabStripPlacement property.  This enables you to direct where the TabItems (tabs) actually get displayed: Top, Left, Right, or Bottom.  This can be set in XAML and also controlled during runtime using the Dock enumeration.

    Each TabItem also has two properties to set content: Header and Content.  Header is where you would put the content for the tab itself and content direct the actual content within the TabItem.  This can be set to literal string values, but they can also be set to other content.  For example, if you want to set the content within the TabItem, you could do something like:

    <ex:TabItem Width="75" Height="20" Header="Third">
        <StackPanel Orientation="Vertical">
            <TextBox x:Name="yourname" />
            <Button Content="Click me" Click="Button_Click" />
            <TextBlock x:Name="resulttext" />
        </StackPanel>
    </ex:TabItem>

    If you wanted to set alternate content as the Header you could likewise do that as well noting the TabItem.Header:

    <ex:TabItem Width="75" Height="20">
        <ex:TabItem.Header>
            <Button Content="foo" />
        </ex:TabItem.Header>
        <Button Content="Click Me" Click="Button_Click_1"/>
    </ex:TabItem>

    Let us all welcome TabControl to the family.  A simple yet probably widely used control is now available for you to think of marvelous uses :-).  Remember, that TabControl (as well as the calendar and date picker controls) is located in the Extended control assembly and not the core.  Here’s an example of a TabControl using some of the methods described above:

    For a video demonstration of using TabControl, visit the Silverlight community learning section and stay updated as the video will be there shortly as well as other great videos on using Silverlight 2.

    Hope this helps!


    This work is licensed under a Creative Commons Attribution By license.

    Wednesday, June 04, 2008 4:50 PM

    PostTypeIcon

Comments.

  • Gravatar
    # re: A new Silverlight control - TabControl


    Awesome! :-)
    Lovely surprise to wake up to...

    6/4/2008 4:56 PM
  • Ben Hayat said:
    Gravatar
    # re: A new Silverlight control - TabControl


    >>For a video demonstration of using TabControl, visit the Silverlight community learning section<<

    Tim, can you be more specific which video and which section?

    BTW, excellent detail blog. TabControls are great for screen real estate!

    ..Ben

    6/4/2008 6:38 PM
  • timheuer said:
    Gravatar
    # re: A new Silverlight control - TabControl


    @Ben: 'stay updated as the video will be there shortly' -- :-) teaser for a preview. It's essentially a walk through of this post, but sometimes it is nice to see it instead of read it. The site will have an update soon and the video will be up there.

    6/4/2008 6:49 PM
  • shaggygi said:
    Gravatar
    # re: A new Silverlight control - TabControl


    Where does the TabPanel fit into the mix? Noticed it in the screenshot. Looks like some really good stuff to be released soon. Is the TabControl the only new control in SL2 B2?

    6/4/2008 7:47 PM
  • Ricky said:
    Gravatar
    # re: A new Silverlight control - TabControl


    Hi there,

    Just wondering if the password textbox and combobox/ dropdown list has been introduced in this release?

    Cheers,
    Ricky.

    6/4/2008 8:59 PM
  • Steve said:
    Gravatar
    # re: A new Silverlight control - TabControl


    Tim, Thanks for showing the example with both xaml and blend. As like most of us SL and WPF are not our 9to5 jobs yet hence I find that I get to play with these things maybe twice a week so after the kids go to bed the first 30mins is spent remember what I have done before. Just the other night I could not remember how to get blend to show the timeline (dont make fun of me, I had issues) so I was typing storyboards into VS2008 until it clicked. An example like this where it shows both is very helpfull.

    I noticed Jess's blog says that this month he plans to focus on UI stuff can you please do some examples of the data side when the bits come out. I have seen so many examples of 'Reading' data and displaying it in SL but I really want the 'Create', 'Update' and 'Delete' examples.

    Thanks again.

    PS last I posted your wife wasn't the best I hope all that is resolved now, and she is 100%

    6/4/2008 9:58 PM
  • combobox? said:
    Gravatar
    # re: A new Silverlight control - TabControl


    Isnt there a combobox in silverlight beta2

    6/4/2008 10:00 PM
  • Gravatar
    # re: A new Silverlight control - TabControl


    What about ComboBox control?
    Is there implementation for that?
    I added the extension library as you explained in your article, but still didn't any Combo - just ListBox.

    6/4/2008 11:28 PM
  • Ricky said:
    Gravatar
    # re: A new Silverlight control - TabControl


    We need comBo box combo box , We need comBo box combo box... We need comBo box combo box.... Vote for combobox combo box, not Hilary Clinton

    :D

    6/5/2008 12:08 AM
  • Gravatar
    # re: A new Silverlight control - TabControl


    You can download a Silverlight ComboBox control at http://labs.componentone.com. The C1.Silverlight assembly includes many commonly used controls such as ComboBox, NumericBox, MaskedTextBox, RichTextBox, PasswordBox, TreeView, etc.

    PS: I hope this doesn't sounds like an ad or anything, it just looks like some people really need a combo ;-)

    6/5/2008 7:20 AM
  • Gravatar
    # re: A new Silverlight control - TabControl


    Who is Hilary Clinton?

    6/5/2008 6:46 PM
  • kiseok said:
    Gravatar
    # re: A new Silverlight control - TabControl


    i am waiting for broswer box control. it is possible?
    :)

    6/6/2008 1:48 AM
  • Gravatar
    # re: A new Silverlight control - TabControl


    looking for a complete example of a DropdownList control in Silverlight2.2 using databind....any help pls

    7/3/2008 4:55 AM
  • Gravatar
    # re: A new Silverlight control - TabControl


    Really love the Tabcontrol, can't wait to try to put a Listbox inside the Tabitem control :)

    Now i just have to wait for the other goodies in Silverlight final. I wonder what other controls would be included in the final. Scott's said it would have 100+ control? I hope so :)

    8/17/2008 5:29 AM

Your Reply.

  Comment Form  

Fields denoted with a "*" are required.

*Your name:
Subject:
Your blog:
Your email:  (will not be displayed)
*Your message:

 
Please add 8 and 8 and type the answer here: