Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Hide Grid Column

Tags:

wpf

grid

I have a xaml grid defined as:

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
    </Grid>

The first column will contain a TextBlock and the second column a TextBox for data capture. How can I toggle the visibility of first column?

like image 695
David Ward Avatar asked Aug 04 '10 14:08

David Ward


People also ask

How to hide column of Grid in WPF?

To hide a column from the GridControl, set the BaseColumn. Visible property to false. To hide column from the Column Chooser, set the column's ColumnBase. ShowInColumnChooser property to false.

How to hide Grid Row in WPF?

Simply do this: rowToHide. Height = new GridLength(0);

How to hide width column in WPF?

Try setting both column definition widths to "Auto". Then in the xaml content for column 2, set it's Visibility to collapsed - this should hide it. When you set it to visible it should show with it's size determined by it's contents. You can give the column a name, and the reference the column in code behind.


1 Answers

The solution to my problem was to change the width of the first column to "Auto". Then I set up the bindings of my first textbox so that its Visibility property was set to Collapsed (not hidden) which results in the column not being rendered.

like image 73
David Ward Avatar answered Nov 15 '22 10:11

David Ward