WPF trigger on datagrid to hide/show columns according to bindings

Posted by Renan on Stack Overflow See other posts from Stack Overflow or by Renan
Published on 2010-12-21T12:41:43Z Indexed on 2010/12/21 15:54 UTC
Read the original article Hit count: 1173

I have a data grid like this:

<DataGrid AutoGenerateColumns="False" CanUserDeleteRows="True"
          HorizontalScrollBarVisibility="Hidden" Margin="10,10,10,10" 
          VerticalScrollBarVisibility="Visible" 
          CanUserAddRows="False" ItemsSource="{Binding ListGestores}"
          ToolTip="Selecione uma linha e pressione DELETE para remover uma unidade.">
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding TB_UNIDADE.DS_NOME_UNIDADE}" CanUserResize="False" Header="Setor" IsReadOnly="True" x:Name=""/>
        <DataGridTextColumn Binding="{Binding TB_UNIDADE.TB_UNIDADE2.DS_NOME_UNIDADE}" CanUserResize="False" Header="Unidade" IsReadOnly="True" x:Name=""/>
        <DataGridTextColumn Binding="{Binding TB_CONTATOS.DS_NOME}" CanUserResize="False" Header="Gestor" IsReadOnly="True" />
    </DataGrid.Columns>
</DataGrid>

The problem is that i need to verify if the 2 column binding is null, and if it is null, i need to Hide it, and Change the Header of the column 1.

I know that i can do that with Triggers, but how exactly??? I started with:

<DataGrid.Triggers>
    <DataTrigger Binding="{Binding TB_UNIDADE.TB_UNIDADE2}" Value="{x:Null}">
        <Setter Property="" Value="" />
    </DataTrigger>
</DataGrid.Triggers>

But i don't know what setter or whatever to put !

Help me =]

© Stack Overflow or respective owner

Related posts about wpf

Related posts about wpf-binding