There is an expander in column 0.
How can the visibility of the stack panels in the neighboring columns be toggled between Visible and Collapsed based on IsExpanded state of the Expander?
<ListView ItemsSource="{Binding Records}">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Records"
Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate DataType="{x:Type local:Record}">
<Expander Header="{Binding Name}">
<ItemsControl ItemsSource="{Binding Limits}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border Width="25"/>
<CheckBox/>
<Border Width="5"/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Expander>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
...
<GridViewColumn Header="HiLimit"
Width="80">
<GridViewColumn.CellTemplate>
<DataTemplate DataType="{x:Type local:Record}">
<StackPanel Width="70">
<Border Height="21"/>
<ItemsControl ItemsSource="{Binding Limits}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding HiLimit}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
GridView columns
I was thinking about using a control template trigger but I'm not sure how to approach that when the cell template needs to be a data template?
There is an expander in column 0.
How can the visibility of the stack panels in the neighboring columns be toggled between Visible and Collapsed based on IsExpanded state of the Expander?
<ListView ItemsSource="{Binding Records}">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Records"
Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate DataType="{x:Type local:Record}">
<Expander Header="{Binding Name}">
<ItemsControl ItemsSource="{Binding Limits}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border Width="25"/>
<CheckBox/>
<Border Width="5"/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Expander>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
...
<GridViewColumn Header="HiLimit"
Width="80">
<GridViewColumn.CellTemplate>
<DataTemplate DataType="{x:Type local:Record}">
<StackPanel Width="70">
<Border Height="21"/>
<ItemsControl ItemsSource="{Binding Limits}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding HiLimit}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
GridView columns
I was thinking about using a control template trigger but I'm not sure how to approach that when the cell template needs to be a data template?
Share Improve this question edited Mar 17 at 15:50 EldHasp 7,9702 gold badges10 silver badges31 bronze badges asked Mar 17 at 13:42 JimJrJimJr 31 bronze badge 2 |1 Answer
Reset to default 0Two main ways.
Add a bool property for IsExpanded to the collection element;
Use the DataGridRow property or create an Attached Property for this.
I show the implementation of the second option using Tag.
<GridViewColumn.CellTemplate>
<DataTemplate DataType="{x:Type local:Record}">
<Expander Header="{Binding Name}"
IsExpanded="{Binding Tag,
Mode=OneWayToSource,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GridViewRowPresenter}}}">
<GridViewColumn.CellTemplate>
<DataTemplate DataType="{x:Type local:Record}">
<StackPanel Width="70"
Visibility="{Binding Tag,
Mode=OneWay,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GridViewRowPresenter}},
Converter={StaticResource bollToVisiblyConverter}}">
P.S. I am writing "in a hurry" here in the editor. Please do not scold me too much for possible minor errors.
GridViewColumn
when the expander in the first columns is collapsed? – Sergey A Kryukov Commented Mar 18 at 4:24