开发者

WPF Hide Grid Column

I have a xaml grid defined as:

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150"/开发者_如何学Go>
            <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?


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.


 <ColumnDefinition>
       <ColumnDefinition.Style>
             <Style TargetType="ColumnDefinition">
                 <Setter Property="Width" Value="*" />
                     <Style.Triggers>
                         <DataTrigger Binding="{Binding IsColumnVisible}" Value="False">
                             <Setter Property="Width" Value="0" />
                         </DataTrigger>
                      </Style.Triggers>
              </Style>
         </ColumnDefinition.Style>
    </ColumnDefinition>

Please do implement INotifyPropertyChanged in your ViewModel

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜