Results 1 to 2 of 2

Thread: Tabless Tabcontrol or Something Similar

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Tabless Tabcontrol or Something Similar

    In the WPF app I'm making at the moment, I need a method that will allow me to click a button and a different "page" in the middle of the window is changed based on button click.

    So, if button 1 is clicked, page 1 is shown and so forth. In WinForms, I'd just make a tabless tabcontrol like so:

    VB.NET Code:
    1. Public Class TabLessTabControl
    2.     Inherits TabControl
    3.     Protected Overrides Sub WndProc(ByRef m As Message)
    4.         'Hide tabs by trapping the TCM_ADJUSTRECT message
    5.         If m.Msg = &H1328 Then
    6.             m.Result = CType(1, IntPtr)
    7.         Else
    8.             MyBase.WndProc(m)
    9.         End If
    10.     End Sub
    11. End Class

    But, that doesn't work in WPF. Does anyone have any ideas on how to duplicate this in WPF or if there's a better method?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Tabless Tabcontrol or Something Similar

    Don't think winforms, ever again. WPF is completely different, and whereas in winforms you often need to resort to intercepting messages to change fundamental control behavior and look, that is completely gone in WPF. In WPF controls are built up using control templates, containing an entire tree of visual elements. For example, a single TextBox might consist of a couple of Borders, containing a ScrollViewer, containing a text element, .. etc. If there is no simple way to achieve what you want (eg, via properties, and there usually aren't many properties to change the looks of controls) then you can always replace the entire visual tree by your own control template. The behavior of the control is kept intact but you can choose what elements are used to depict which part of the control.

    I'm telling you this because I'm not sure what the easiest way to do this would be in WPF, but you always have the option of completely restyling the TabControl by supplying your own template, and simply leaving out the tab headers.

    For a simpler method, I am assuming the TabControl has an ItemsContainerStyle property. This would be the style for its items (eg: the tab pages). Each visual element in WPF also has a Style that defines what values certain properties have, and can even change these values when certain trigger conditions are met (eg: the mouse is hovering over the element, it's selected, etc).

    You might be able to do something as simple as this (completely untested): just give the items a Style that collapses the tab page. I am guessing this would only collapse the headers, but I'm not sure. Give it a try.
    xml Code:
    1. <TabControl>
    2.     <TabControl.ItemsContainerStyle>
    3.         <Style TargetType="{x:Type TabItem}">
    4.             <Setter Property="Visibility" Value="Collapsed"/>
    5.         </Style>
    6.     </TabControl.ItemContainerStyle>
    7. </TabControl>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width