我希望值To="200.0"
自动等于网格大小
<ListBox HorizontalAlignment="Stretch" Grid.Column="1"
Margin="12,90,12,12"
Name="listBox1"
Opacity="0.6"
VerticalAlignment="Stretch" BorderThickness="0.5" BorderBrush="White">
<ListBox.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="listBox1"
Storyboard.TargetProperty="Width"
From=" 0.0" To="200.0" />
<DoubleAnimation Storyboard.TargetName="listBox1"
Storyboard.TargetProperty="Height"
From="0.0" To="200.0" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ListBox.Triggers>
</ListBox>
答案 0 :(得分:1)
尝试这样的事情:
<Grid Name="test">
<ListBox HorizontalAlignment="Stretch" Name="listBox1"
VerticalAlignment="Stretch" BorderThickness="0.5" BorderBrush="Black">
<ListBox.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="listBox1"
Storyboard.TargetProperty="Width"
From="0.0" To="{Binding ElementName=test,Path=ActualWidth}" />
<DoubleAnimation Storyboard.TargetName="listBox1"
Storyboard.TargetProperty="Height"
From="0.0" To="{Binding ElementName=test,Path=ActualHeight}" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ListBox.Triggers>
</ListBox>
</Grid>
我使用了ElementName绑定而不是RelativeSource绑定,因为我无法使RelativeSource工作。我猜是因为故事板不是与列表框相同的视觉/控制树的一部分。