How to binding to the actual width and height of the control in doubleanimation?
-
Hi, I add a expander to a window and the double animation when is expanded. However, the to property of the doubleanimation is hardcoded, in my example, the "to" property is 200 and 400. I want to ask that how could it binding to the actual width or height of the expander control? Is this possible?
<Expander Grid.Column="3" Grid.RowSpan="2" Header="expander1" Margin="3,12,-83,18" Name="expander1" BorderBrush="Red" BorderThickness="2" Width="200" Height="400">
<StackPanel>
<Button Width="100">This is the button one</Button>
<Button Width="100">This is the button two</Button>
</StackPanel><Expander.Triggers> <EventTrigger RoutedEvent="Expander.Expanded"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="expander1" Storyboard.TargetProperty="Width" From="0" To="200" Duration="0:0:0.25" /> <DoubleAnimation Storyboard.TargetName="expander1" Storyboard.TargetProperty="Height" From="0" To="400" Duration="0:0:0.25" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Expander.Triggers> </Expander>
thanks.
-
Hi, I add a expander to a window and the double animation when is expanded. However, the to property of the doubleanimation is hardcoded, in my example, the "to" property is 200 and 400. I want to ask that how could it binding to the actual width or height of the expander control? Is this possible?
<Expander Grid.Column="3" Grid.RowSpan="2" Header="expander1" Margin="3,12,-83,18" Name="expander1" BorderBrush="Red" BorderThickness="2" Width="200" Height="400">
<StackPanel>
<Button Width="100">This is the button one</Button>
<Button Width="100">This is the button two</Button>
</StackPanel><Expander.Triggers> <EventTrigger RoutedEvent="Expander.Expanded"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="expander1" Storyboard.TargetProperty="Width" From="0" To="200" Duration="0:0:0.25" /> <DoubleAnimation Storyboard.TargetName="expander1" Storyboard.TargetProperty="Height" From="0" To="400" Duration="0:0:0.25" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Expander.Triggers> </Expander>
thanks.
You could always replace this with
To="{Binding ElementName=expander1, Path=ActualWidth}"
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
-
You could always replace this with
To="{Binding ElementName=expander1, Path=ActualWidth}"
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
I tried that. It works. Thanks a lot. Eric
-
I tried that. It works. Thanks a lot. Eric
You're welcome. I'm glad to help - and a 5 for the thanks. :-D
"WPF has many lovers. It's a veritable porn star!" - Josh Smith