Here's the idea: I need an expand/collapse button in my DataGridTemplateColumn
to allow user to expand a cell to view full contents, or collapse it to only see the first line. Here's my template:
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<local:ExpandCollapseButton />
<TextBlock x:Name="MyTB" Text="{Binding Body}" Grid.Column="1" TextTrimming="WordEllipsis" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
ExpandCollapseButton
is a simple UserControl
that toggles between + and - icons when clicked. It has got a read/write bool
property named IsExpanded
.
I'm now trying to add a simple Trigger
to ExpandCollapseButton
's triggers, which would simply set TextBlock
's TextTrimming
property to WordEllipsis
in collapsed state and set it to None
in expanded state, but can't figure out correct way of doing it. I tried adding the following code under my Expand control above:
<local:ExpandCollapseButton.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter TargetName="MyTB" Property="TextTrimming" Value="None" />
</Trigger>
</local:ExpandCollapseButton.Triggers>
but this gives error saying Cannot find the static member 'IsExpandedProperty' on the type 'ContentPresenter'
, which I'm unable to comprehend.