Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide a control so that it no longer takes up space in WPF?

I have a DataTemplate that I am using for a cell in a gridview. I would like to switch between the progress bar and the text/link block. Is there a way to hide an element so that it is removed from the flow and takes up no space while it is hidden (like "display:none" in CSS)? Is there a better way to approach this?

DataTemplate looks like:

<DataTemplate x:Key="DataTemplate2">
    <StackPanel Height="40">
        <TextBlock Visibility="{Binding ButtonVisibility}">
            <Hyperlink Click="btn_Authorise">
                <InlineUIContainer>
                    <TextBlock Text="{Binding Button}" />
                </InlineUIContainer>
            </Hyperlink>
        </TextBlock>
        <ProgressBar Value="{Binding Progress}"
                     Visibility="{Binding ProgressVisibility}"
                     Height="15"
                     Width="150"
                     Background="{DynamicResource NormalBrush}"
                     BorderThickness="0"
                     BorderBrush="#FF8D8D8D"
                     Style="{DynamicResource ProgressBarStyle1}" />
    </StackPanel>
</DataTemplate>
like image 405
dan Avatar asked May 30 '11 01:05

dan


2 Answers

Visibility.Collapsed is probably what you need (as opposed to Visibility.Hidden which still makes the control take part in layout calculations)

Also see the Visibility enumeration reference.

like image 164
H.B. Avatar answered Nov 15 '22 09:11

H.B.


Yep.

Visibility is an enumeration, Visible, Hidden, and Collapsed. Hidden is just non-visible, whereas Collapsed means it takes no space also

like image 29
Elad Katz Avatar answered Nov 15 '22 11:11

Elad Katz