N
N
Nikita Tratorov2012-10-19 02:16:38
.NET
Nikita Tratorov, 2012-10-19 02:16:38

WPF: Expander DesiredHeight issue with XAML animation

Greetings colleagues!
Knowledgeable people, please tell me how to solve the problem.
There is a simple Expander, it has a Grid with fields. The Expander has an unroll animation so that it falls out smoothly. It works if you explicitly specify what height it should strive for (To = "300"), but if you try to use DesiredHeight, then MS VS swears a lot, because it fails to render the form with this Expander.

Here is the actual XAML

<Expander Header="Реквизиты юридического лица" HorizontalAlignment="Stretch" Margin="10" Name="Expander1" VerticalAlignment="Top" ExpandDirection="Down" >
                    <Expander.Content>
                        <Grid Height="128">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="170*" />
                            <ColumnDefinition Width="331*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="32" />
                            <RowDefinition Height="32" />
                            <RowDefinition Height="32" />
                            <RowDefinition Height="32" />
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0" Grid.Column="0" Name="Label7" HorizontalAlignment="Right" Margin="5,0,0,5">Название орг.</Label>
                        <TextBox Grid.Row="0" Grid.Column="1" Name="TextBox7" Margin="5" />
                        <Label Grid.Row="1" Grid.Column="0" Name="Label3" HorizontalAlignment="Right" Margin="5,0,0,5">ИНН</Label>
                        <TextBox Grid.Row="1" Grid.Column="1" Name="TextBox3" Margin="5" />
                        <Label Grid.Row="2" Grid.Column="0" Name="Label4" HorizontalAlignment="Right" Margin="5,0,0,5">КПП</Label>
                        <TextBox Grid.Row="2" Grid.Column="1" Name="TextBox4" Margin="5" />
                        <Label Grid.Row="3" Grid.Column="0" Name="Label5" HorizontalAlignment="Right" Margin="5,0,0,5">Адрес</Label>
                        <TextBox Grid.Row="3" Grid.Column="1" Name="TextBox5" Margin="5" />
                    </Grid></Expander.Content>
                    <Expander.Style>
                        <Style>
                            <Style.Triggers>
                                <Trigger Property="Expander.IsExpanded" Value="True">
                                    <Trigger.EnterActions>
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <DoubleAnimation From="0" To="{Binding ElementName=Content, Path=DesiredHeight}" Duration="0:0:0.2" Storyboard.TargetProperty="Content.Height" />
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </Trigger.EnterActions>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </Expander.Style>
                </Expander>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Tratorov, 2012-10-20
@NikitaTratorov

There is a small victory in solving this problem.
It turns out that if you don't know where you want to go in the animation, it's enough to specify the initial value (From).
In other words, writing:
<DoubleAnimation From="0" Duration="0:0:0.2" Storyboard.TargetProperty="Content.Height" />
works! Expamder smoothly unfolds to some of his own, known to him alone.
Now another problem is also to smoothly roll it up. I tried adding a logical way (To):
<Trigger.ExitActions>
<DoubleAnimation To="0" Duration="0:0:0.2" Storyboard.TargetProperty="Content.Height" />
</Trigger.ExitActions>
but didn't succeed . There is no animation. Does anyone have any thoughts?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question