0

I have a DataGrid with the DataContext as a list of objects with many properties.

All of the columns are bound to a different property of said object type.

There is a text property that I only care about if another bool property is set to "true" - when it is "false" I don't want the text property to show at all.

Do you have any way to suggest doing this?

I was thinking of something along the lines of:

foreach (var cur in DG.ItemsSource) {
 if (!cur.BoolThatSignifiesIfICareAboutOtherProperty) {
  //some code that will make the cell for cur.PropertyIMayOrMayNotCareAbout
  //appear empty even though that property does have a value that the column
  //is bound to
 }
}

** edit **

It was suggested that I use a data trigger. So this is what I tried, but it also doesn't work. Nor does it give any errors, so I don't know what I'm doing wrong.

Here is what I have so far. It doesn't work, though. Please let me know what I'm doing wrong:

 <DataGridTextColumn Header="EndDate" Binding="{Binding Path=EndDate, Converter={StaticResource DT2D}}">
                <DataGridTextColumn.CellStyle>
                    <Style TargetType="{x:Type DataGridCell}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=DoICare}" Value="False">
                                <Setter Property="Content" Value=" " />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </DataGridTextColumn.CellStyle>
            </DataGridTextColumn>
Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • You're looking for a `DataTrigger`. – Federico Berasategui Jan 24 '14 at 17:57
  • @HighCore so I have never used a DataTrigger before. Here is what I think makes the most sense for what I want here, but it isn't working. It doesn't actually make the cell appear empty - it still shows the data: - I'm going to post it as an edit to the question because I didn't realize that hitting "enter" here posts the comment instead of letting me type more –  Jan 24 '14 at 20:13

1 Answers1

0

So this is how I solved it - I just had some of the tags wrong:

 <DataGridTextColumn Header="EndDate" Binding="{Binding Path=EndDate, Converter={StaticResource DT2D}}">
                <DataGridTextColumn.ElementStyle>
                    <Style TargetType="{x:Type TextBlock}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=DoICare}" Value="False">
                                <Setter Property="Visibility" Value="Hidden" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </DataGridTextColumn.ElementStyle>
            </DataGridTextColumn>