2012-02-28 71 views
3

我有一個單獨的XAML文件看起來像這樣:如何提取Viewport3d.Triggers故事板在WPF

<Viewport3D x:Name="ZAM3DViewport3D" ClipToBounds="true" Width="400" Height="300" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006" xmlns:c="http://schemas.openxmlformats.org/markup-compatibility/2006" c:Ignorable="d"> 
<Viewport3D.Triggers> 
    <EventTrigger RoutedEvent="Viewport3D.Loaded"> 
     <EventTrigger.Actions> 
      <BeginStoryboard> 
       <Storyboard Duration="Forever" FillBehavior="HoldEnd" BeginTime="0:0:0" x:Name="storyboard" d:StoryboardName="OnLoaded"> 
..... 

而且我已經在計劃中的代碼,該段:

.... 
FileStream fs = new FileStream(mm.path, FileMode.Open, FileAccess.Read); // 
Viewport3D v3d = (Viewport3D)XamlReader.Load(fs); 
.... 

我想知道如何從EventTrigger.Actions中提取故事板。我想這應該是這樣的:

Storyboard sb = (Storyboard)v3d.Triggers[0].... 

有誰知道如何做到這一點?

回答

1

如果您需要StoryboardTriggers旁邊的其他位置將其定義爲資源。然後你可以使用StaticResourceBeginStoryboard中引用它,在代碼中你可以用FindResource找到它,或者直接從Resources屬性中找到它。

<Viewport3D.Resources> 
    <Storyboard x:Key="ThatSb">...</Storyboard> 
<Viewport3D.Resources> 
<!-- .... --> 
    <BeginStoryboard Storyboard="{StaticResource ThatSb}"/> 
Storyboard sb = (Storyboard)v3d.Resources["ThatSb"]; 

沒有這麼不錯的選擇實際上是鑄造你的一路下跌,像

var trigger = (EventTrigger)v3d.Triggers[0]; 
var beginSb = (BeginStoryboard)trigger.Actions[0]; 
var sb = beginSb.Storyboard;