Bonsoir,

J'essai de mettre en place une petite animation sur la hauteur d'un contrôle ListBox, une valeur en dur fonctionne parfaitement sauf que je souhaiterais que cette valeur soit plutôt récupérer sur l'objet ListBox lui-même.

Voici le code posant problème :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
<ListBox x:Name="lstRadio" ScrollViewer.VerticalScrollBarVisibility="Hidden" Height="0" MaxHeight="135">
                            <ListBoxItem>
                                <TextBlock Height="45">Alençon</TextBlock>
                            </ListBoxItem>
                            <ListBoxItem>
                                <TextBlock Height="45">Sablé-sur-Sarthe</TextBlock>
                            </ListBoxItem>
                            <ListBoxItem>
                                <TextBlock Height="45">Mamers</TextBlock>
                            </ListBoxItem>
 
                            <ListBox.Style>
                                <Style TargetType="{x:Type ListBox}">
                                    <Style.Triggers>
                                        <Trigger Property="IsEnabled" Value="True">
                                            <Trigger.EnterActions>
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)">
                                                            <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                                                            <EasingDoubleKeyFrame KeyTime="0:0:0.20" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBox}}, Path=MaxHeight}"/>
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </Trigger.EnterActions>
                                            <Trigger.ExitActions>
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)">
                                                            <EasingDoubleKeyFrame KeyTime="0" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBox}}, Path=MaxHeight}"/>
                                                            <EasingDoubleKeyFrame KeyTime="0:0:0.20" Value="0"/>
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </Trigger.ExitActions>
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </ListBox.Style>
                        </ListBox>
Sur {Binding RelativeSource={RelativeSource AncestorType={x:Type ListBox}}, Path=MaxHeight} il me renvoi l'erreur suivante :

InvalidOperationException*: Impossible de figer cette arborescence de chronologie Storyboard pour l¹utiliser sur les threads.

Alors après quelques recherches, j'ai trouvé ce post : https://social.msdn.microsoft.com/Fo...tion?forum=wpf

Est-ce bien dans ce cas que je me trouve ? Si oui, auriez-vous une idée d'arriver à mes fins ?

Merci.