我正在尝试使用动画来控制图像的幻灯片。
用户在txtaddress中输入文件夹路径,点击btnGo,程序会在该文件夹中显示每个图像两秒钟。
然而,我正在利用动画来控制这一点。当它开始幻灯片放映时,我收到错误“无法解析属性路径中的所有属性引用”imgMain.Source“
我的完整代码如下。有什么想法吗?
Imports System.IO
Imports System.Windows.Media.Animation
Class MainWindow
Private Property ImageSource As String
Private Sub btnGo_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnGo.Click
'Get file list
Dim fileList(0) As String
Dim btm(0) As BitmapImage
Dim dir1 As New DirectoryInfo(txtAddress.Text)
Dim anim As New ObjectAnimationUsingKeyFrames
For Each fi In dir1.GetFiles("*.bmp")
fileList(UBound(fileList)) = fi.Name
ReDim Preserve fileList(UBound(fileList) + 1)
Next
For Each fi In dir1.GetFiles("*.png")
fileList(UBound(fileList)) = fi.Name
ReDim Preserve fileList(UBound(fileList) + 1)
Next
For Each fi In dir1.GetFiles("*.jpg")
fileList(UBound(fileList)) = fi.Name
ReDim Preserve fileList(UBound(fileList) + 1)
Next
'Create animation
anim.Duration = TimeSpan.FromSeconds(UBound(fileList) * 2)
Dim idx As Integer
For idx = 0 To UBound(fileList) - 1
btm(idx) = New BitmapImage(New Uri(txtAddress.Text & "\" & fileList(idx), UriKind.Absolute))
anim.KeyFrames.Add(New DiscreteObjectKeyFrame(btm(idx), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(idx * 2))))
ReDim Preserve btm(UBound(btm) + 1)
Next
Dim sBoard As New Storyboard
sBoard.Children.Add(anim)
Storyboard.SetTargetName(anim, imgMain.Name)
Storyboard.SetTargetProperty(anim, New PropertyPath("imgMain.Source"))
sBoard.Begin(Me)
End Sub
End Class