好吧,嘗試和錯誤後,我想出了一個解決方案,但它不完全是我想要的(故事板在數據模板之外定義,也許代碼較少,我認爲它太多隻是翻轉圖像),但非常關。
如此,例如列表框:
<ListBox x:Name="lbxCardTable" SelectionChanged="lbxCardTable_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="imgContainer">
<Image x:Name="img" Source="{Binding } />
<Grid.Resources>
<Storyboard x:Name="itemSb">
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="imgContainer"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="90"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Grid.Resources>
<Grid.Projection>
<PlaneProjection/>
</Grid.Projection>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
而後面的代碼:
private void lbxCardTable_SelectionChanged(object sender, SelectionChangedEventArgs e) {
object selectedItem = lbxCardTable.SelectedItem;
ListBoxItem lbitem = (ListBoxItem)lbxCardTable.ItemContainerGenerator.ContainerFromItem(selectedItem);
var border =(Border) VisualTreeHelper.GetChild(lbitem, 0);
var mcontentcontrol =(ContentControl) VisualTreeHelper.GetChild(border, 0);
var contentpresenter =(ContentPresenter) VisualTreeHelper.GetChild(mcontentcontrol, 0);
var mgrid=(Grid)VisualTreeHelper.GetChild(contentpresenter,0);
Storyboard sb = mgrid.Resources["itemSb"] as Storyboard;
if (sb.GetCurrentState() != ClockState.Stopped) {
sb.Stop();
}
sb.Begin();
}