我想某種動畫添加到項目,因爲它們可以添加到一個列表框,因爲這個博客聲稱做 Link動畫列表框項目在Silverlight
麻煩的是,當我加我VisualStateGroup使用我的BeforeLoaded和Loaded狀態名稱,項目在ListBox中根本無法呈現。當我懸停時,我得到藍色突出顯示,點擊選擇時顯示更亮的藍色,但列表框項目(隨機矩形)的實際內容不存在。
當我刪除該組時,矩形呈現完美,但沒有任何類型的動畫(顯然)。附加是ListBox的ItemContainerStyle的完整樣式。代碼的其餘部分是從鏈接逐字。
<Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
<Setter Property="Padding" Value="3"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="TabNavigation" Value="Local"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="LayoutStates">
<VisualState x:Name="BeforeLoaded">
<Storyboard>
<DoubleAnimation
Duration="00:00:00"
By="-196"
Storyboard.TargetName="contentProjection"
Storyboard.TargetProperty="GlobalOffsetX" />
<DoubleAnimation
Duration="00:00:00"
By="-180"
Storyboard.TargetName="contentProjection"
Storyboard.TargetProperty="RotationY" />
<DoubleAnimation
Duration="00:00:00"
By="-270"
Storyboard.TargetName="contentProjection"
Storyboard.TargetProperty="RotationX" />
</Storyboard>
</VisualState>
<VisualState x:Name="Loaded">
<Storyboard>
<DoubleAnimation
Duration="00:00:01"
To="0"
Storyboard.TargetName="contentProjection"
Storyboard.TargetProperty="GlobalOffsetX" />
<DoubleAnimation
Duration="00:00:01"
To="0"
Storyboard.TargetName="contentProjection"
Storyboard.TargetProperty="RotationY" />
<DoubleAnimation
Duration="00:00:01"
To="0"
Storyboard.TargetName="contentProjection"
Storyboard.TargetProperty="RotationX" />
</Storyboard>
</VisualState>
<VisualState x:Name="Unloaded" />
</VisualStateGroup>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation Duration="0" To=".35" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="contentPresenter"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimation Duration="0" To=".75" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor2"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="FocusVisualElement">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="fillColor" Fill="#FFBADDE9" IsHitTestVisible="False" Opacity="0" RadiusY="1" RadiusX="1"/>
<Rectangle x:Name="fillColor2" Fill="#FFBADDE9" IsHitTestVisible="False" Opacity="0" RadiusY="1" RadiusX="1"/>
<!--<ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/>-->
<ContentPresenter x:Name="contentPresenter"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}">
<ContentPresenter.Projection>
<PlaneProjection x:Name="contentProjection">
</PlaneProjection>
</ContentPresenter.Projection>
</ContentPresenter>
<Rectangle x:Name="FocusVisualElement" RadiusY="1" RadiusX="1" Stroke="#FF6DBDD1" StrokeThickness="1" Visibility="Collapsed"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
你讀過Petzold的文章http://msdn.microsoft.com/en-us/magazine/ff798276.aspx? – Denis 2010-12-21 18:29:49
如果我仔細閱讀,我會發現安東尼在下面提到的錯字。謝謝。 – 2010-12-21 19:14:58