I hope this looks ok, haven't posted code before.
I found this solution to expanding/collapsing listboxitems. The grid below is what holds my content. Its height is the contents actual height within the stackpanel (x:Name="stack") and stored in the Grid's Tag property. the DataTrigger animates the Tag. The custom:XSButton comes from Andy L's CustomControls, and acts as a ToggleButton. Just need this converter for the Grid height.
public class MultiplyConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
double result = 1.0;
for (int i = 0; i < values.Length; i++)
{
if (values[i] is double)
result *= (double)values[i];
}
return result;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new Exception("Not implemented");
}
}
The Grid
<Grid x:Name="Grid" Grid.ColumnSpan="3" Grid.Row="1" >
<Grid.Tag>
<System:Double>0.0</System:Double>
</Grid.Tag>
<Grid.Height>
<MultiBinding Converter="{StaticResource multiplyConverter}">
<Binding Path="ActualHeight" ElementName="stack"/>
<Binding Path="Tag" RelativeSource="{RelativeSource Self}" />
</MultiBinding>
</Grid.Height>
<custom:XSButton IsChecked="{Binding
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListBoxItem}},
Path=IsSelected}" Background="Transparent" BorderThickness="0" BorderBrush="Transparent"
ClickMode="Press"
Foreground="Transparent" Style="{DynamicResource XSButtonStyle1}" >
<StackPanel x:Name="stack">
<TextBlock Text="{Binding Text}" FontSize="13.333" TextWrapping="Wrap" Foreground="#FFC0C7C8"/>
<TextBlock Text="{Binding Status_Message}" FontSize="13.333" TextWrapping="Wrap" Foreground="#FFC0C7C8"/>
</StackPanel>
</custom:XSButton>
</Grid>
the DataTrigger for expanding/collapsing
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="Grid" Storyboard.TargetProperty="Tag" To="1" Duration="0:0:0.4"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="Grid" Storyboard.TargetProperty="Tag" To="0" Duration="0:0:0.4"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</DataTemplate.Triggers>