为什么在使用WPF时无法访问故事板。在Silverlight中,完全相同的代码可以工作。
Codebehind VB
Public Class UserControl1
Private Sub UserControl1_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
Me.storyboardBlend.Begin()
End Sub
End Class
XAML:
<UserControl x:Class="UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Image x:Name="imgOn" Source="/OUTPUT%20-%20WPF01;component/Images/Disk.png" />
<Grid.Resources>
<Storyboard x:Key="storyboardBlend" x:Name="storyboardBlend">
<DoubleAnimation x:Name="AnimationOpacityOn" Storyboard.TargetName="imgOn" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
</Storyboard>
</Grid.Resources>
</Grid>
</UserControl>
答案 0 :(得分:0)
使用字符串作为键现在可用于故事板。但我仍然无法访问动画参数,这是下一步。
XAML部分:
<Grid.Resources>
<Storyboard x:Key="storyboardBlend" x:Name="storyboardBlend">
<DoubleAnimation x:Name="AnimationOpacityOn" Storyboard.TargetName="imgOn" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
<DoubleAnimation x:Name="AnimationOpacityOff" Storyboard.TargetName="imgOff" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
<DoubleAnimation x:Name="AnimationOpacitOnGlow" Storyboard.TargetName="imgOnGlow" Storyboard.TargetProperty="Opacity" Duration="0:0:1.500" To="1" />
</Storyboard>
</Grid.Resources>
Hackbe in Codebehind无法正常工作:
Private _Checked As Boolean
Public Property Checked As Boolean
Get
Return _Checked
End Get
Set(ByVal value As Boolean)
_Checked = value
Dim storyboard As Storyboard = LayoutTextImage.Resources("storyboardBlend")
storyboard.Stop()
If _Checked = True Then
Dim Anim As DoubleAnimation
Anim = storyboard("AnimationOpacityOn")
Anim.To = 1
Anim = Me.FindResource("AnimationOpacityOff")
Anim.To = 0
Anim = Me.FindResource("AnimationOpacityOnGlow")
Anim.To = 1
'Dim storyboard As Storyboard = Me.FindResource("storyboardBlend")
storyboard.Begin()
Else
Dim Anim As DoubleAnimation
Anim = Me.FindResource("AnimationOpacityOn")
Anim.To = 0
Anim = Me.FindResource("AnimationOpacityOff")
Anim.To = 1
Anim = Me.FindResource("AnimationOpacityOnGlow")
Anim.To = 0
storyboard.Begin()
End If
End Set
End Property