2012-11-02 117 views
0

我是新來使用WPF故事板,這裏是我的代碼:WPF故事板事件綁定

<StackPanel> 

    <Border Grid.Row="0" Background="Black" Height="40" Name="Border1"></Border> 

    <Grid Height="0" Name="MyGrid" Background="Green"> 
     <Grid.Triggers> 
      <EventTrigger RoutedEvent="UserControl.Loaded"> 
       <BeginStoryboard> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetName="MyGrid" 
        Storyboard.TargetProperty="Height" From="0" To="40" 
        Duration="0:0:1" BeginTime="0:0:0"/> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </Grid.Triggers> 
    </Grid> 

</StackPanel> 

我想改變觸發故事板開始Border1.MouseEnter事件。

這可能嗎?

感謝名單

回答

1

在這種情況下,你應該觸發器移動到邊境控制:

<StackPanel> 

<Border Grid.Row="0" Background="Black" Height="40" Name="Border1"> 
    <Border.Triggers> 
     <EventTrigger RoutedEvent="Border.MouseEnter"> 
      <BeginStoryboard> 
       <Storyboard> 
        <DoubleAnimation Storyboard.TargetName="MyGrid" 
         Storyboard.TargetProperty="Height" From="0" To="40" 
         Duration="0:0:1" BeginTime="0:0:0"/> 
       </Storyboard> 
      </BeginStoryboard> 
     </EventTrigger> 
    </Border.Triggers> 
</Border> 

<Grid Height="0" Name="MyGrid" Background="Green"> 

</Grid> 

+0

哇,不敢相信我沒想到!但就像我說的那是我第一次嘗試。感謝名單! –

0

我真的沒有嘗試,但這應該工作:

<StackPanel> 
<StackPanel.Triggers> 
    <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="Border1"> 
     <BeginStoryboard> 
      <Storyboard> 
       <DoubleAnimation Storyboard.TargetName="MyGrid" 
        Storyboard.TargetProperty="Height" From="0" To="40" 
        Duration="0:0:1" BeginTime="0:0:0"/> 
      </Storyboard> 
     </BeginStoryboard> 
    </EventTrigger> 
</StackPanel.Triggers> 
     <Border Grid.Row="0" Background="Black" Height="40" Name="Border1"></Border> 
     <Grid Height="0" x:Name="MyGrid" Background="Green" VerticalAlignment="Bottom"/> 
</StackPanel> 
+0

這將不起作用,因爲如果您使用SourceName,則邊框必須是網格的子節點。 – Sukram

+0

是的。對不起。我修好了,但我遲到了;)謝謝 –