0

I have a binding ShowingRecentDocuments that returns a boolean value. Based on this boolean value I would like to show one of two columns in a GridView:

      <ListView ItemsSource="{Binding ModelItems, Mode=OneWay}">
        <ListView.View>
          <GridView>
            <GridViewColumn Header="Templates" 
                            DisplayMemberBinding="{Binding PrettyName}" />

            //If ShowingRecentDocuments == true, show this column
            <GridViewColumn Header="Last Modified" 
                            DisplayMemberBinding="{Binding TimeModified}"/>

            //else show this column
            <GridViewColumn Header="Last Opened"
                            DisplayMemberBinding="{Binding LastOpened}"/>
          </GridView>
        </ListView.View>
      </ListView>

I can't seem to use a DataTrigger within a GridViewColumn, but instead only within GridViewColumn.CellTemplate. How could I go about changing the visibility (or equivalent) of the columns for this task?

monadoboi
  • 1,651
  • 3
  • 16
  • 26
  • 1
    there is a qustion (with answers) about changing visibility. another solution is making static prop `ShowingRecentDocuments` in Model, making static prop `OpenedOrModifiedHeader => ShowingRecentDocuments ? "Last Modified" : "Last Opened"` making readonly prop `OpenedOrModified => ShowingRecentDocuments ? TimeModified : LastOpened` bind `OpenedOrModifiedHeader` to `Header` and `OpenedOrModified` to `DisplayMemberBinding` – Selvin Oct 28 '19 at 10:58

1 Answers1

1

I see two options.

  1. You can define to ListViews with the same data and manipulating their visibility. This would mean you have always 2 ListViews in the view which is ugly and cost performance.
  2. You can adapter these answer and define an attacked property that manage the visibility of the columns.

I would prefer the second one.

0xBADF00D
  • 980
  • 1
  • 12
  • 25