我正在尝试使用动画来控制图像的幻灯片。
用户在 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