4

I have a quick question regarding visibility of windows in an application. According to... http://msdn.microsoft.com/en-us/library/system.windows.visibility.aspx (its short)

When a window is collapsed no space is reserved for the window in layout. When a window is hidden space is reserved for the window in layout.

I'm confused here, what is the layout referring to? Is it referring to window space?

2
  • Assume you page through a number of records. You want a button to be visible or not based on some property. If you set it to collapsed then other content will move but if you set it to hidden other content will not. In that situation I would typically use hidden so Window content would not move around.
    – paparazzo
    Commented Oct 29, 2013 at 12:49
  • Wow thanks for all the responses, thanks guys!
    – Ben Cheng
    Commented Oct 30, 2013 at 1:45

4 Answers 4

9

Here's an illustration:

 <Grid>
        <TabControl>
            <TabItem Header="Visible"></TabItem>
            <TabItem Visibility="Hidden" Header="Hidden">Hidden</TabItem>
            <TabItem Visibility="Hidden" Header="Hidden">Hidden</TabItem>
            <TabItem Visibility="Hidden" Header="Hidden">Hidden</TabItem>
            <TabItem Header="Visible"></TabItem>
            <TabItem Header="Visible"></TabItem>
            <TabItem Header="Visible"></TabItem>
        </TabControl>
    </Grid>

Will render this:
enter image description here

And this XAML:

<Grid>
    <TabControl>
        <TabItem Header="Visible"></TabItem>
        <TabItem Visibility="Collapsed" Header="Collapsed">Collapsed</TabItem>
        <TabItem Visibility="Collapsed" Header="Collapsed">Collapsed</TabItem>
        <TabItem Visibility="Collapsed" Header="Collapsed">Collapsed</TabItem>
        <TabItem Header="Visible"></TabItem>
        <TabItem Header="Visible"></TabItem>
        <TabItem Header="Visible"></TabItem>
    </TabControl>
</Grid>

Will render this:

enter image description here

So, Collapsed will not save the space, whereas Hidden will.

0
1

No, its referring to the whole window you are looking at.

Lets say, you have at the top of the screen a Red Block (20px height) and below the Red Block you have a title.

Hidden: The Red Block is NOT visible, but the space it normally reserves, is still reserved, meaning the Title is is 20px away from the top of the screen

Collapsed: The Red Block is NOT visible together with the reserved space (the 20px height), meaning the Title is located at the top of the screen

0

The visibility does not only refer to windows, but all controls. If you use a layout that automatically places its child controls that it makes a difference if you use 'hidden' or 'collapsed'. 'hidden' means that the layout control still "reserves space" for it when arranging its children, while 'collapsed' means that the layout is not reserving any space for it.

0

Layout is basically the overall placing of your controls within the form so if its collapsed that means it would be abscent in the UI and its place would be utilized by other controls however when its hidden it would be just invisible to user however its place can not be occupied by any other control its just not visible to user.

Not the answer you're looking for? Browse other questions tagged or ask your own question.