7. ウインドゥの制御
Public Class WPFWindowActivity
Inherits CodeActivity
Public Property Window As InArgument(Of Window)
Public Property SetTopMost As InArgument(Of Boolean) = True
Public Property SetFullScreen As InArgument(Of Boolean) = False
Protected Overrides Sub Execute(context As CodeActivityContext)
Dim target = context.GetValue(Me.Window)
target.Topmost = context.GetValue(Me.SetTopMost)
If context.GetValue(Me.SetFullScreen) Then
target.WindowStyle = WindowStyle.None
target.WindowState = WindowState.Maximized
End If
target.Show()
あらかじめ
End Sub
End Class
「用意されたウインドゥを表示」する
単に表示するだけならこの程度なので非常に簡単
8. テキスト表示
Dim displayObject As TextBlock = Nothing
If target.Dispatcher.CheckAccess Then
displayObject = TryCast(target.FindName(contentName), TextBlock)
Else
Dim result = target.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Input,
Function() target.FindName(contentName))
If result IsNot Nothing Then displayObject = TryCast(result, TextBlock)
End If
If displayObject Is Nothing Then Return
‘1文字ずつ表示
Dim dispText As New Text.StringBuilder
For Each mesChar In message.ToCharArray
If displayObject.Dispatcher.CheckAccess Then
displayObject.Inlines.InsertAfter(displayObject.Inlines.FirstInline,
New Run() With {.Text = mesChar})
Else
Dim result = displayObject.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Background,
New Action(Sub() displayObject.Text = dispText.ToString))
End If
DispatcherHelper.DoEvents()
System.Threading.Thread.Sleep(delayTime)
dispText.Append(mesChar)
Next
意外に多くのロジックが必要
'最後の文字を表示
If displayObject.Dispatcher.CheckAccess Then
displayObject.Text = dispText.ToString
Else
Dim result = displayObject.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Background,
New Action(Sub() displayObject.Text = dispText.ToString))
End If
DispathcerHelper.DoEvents()
9. フェードインなどのエフェクト
Public Property DelayTime As InArgument(Of Integer) = 5
Public Property StartValue As InArgument(Of Double) = 0
Public Property EndValue As InArgument(Of Double) = 1
-------------------------------------------(省略)-----------------------------------------------------
Dim fadeinAnime As New DoubleAnimation With {
.From = sValue, .To = eValue,
.Duration = New Duration(TimeSpan.FromSeconds(delay))
}
Dim fadeinStoryboard As New Storyboard
fadeinStoryboard.Children.Add(fadeinAnime)
Storyboard.SetTargetName(fadeinAnime, contentName)
Storyboard.SetTargetProperty(fadeinAnime, New PropertyPath(UIElement.OpacityProperty))
AddHandler fadeinStoryboard.Completed, AddressOf StateInvalidated
fadeinStoryboard.Begin(displayObject)
Do Until _commitAnime エフェクトを行おうとすると
DispatcherHelper.DoEvents() 多くのロジックが必要になる
Loop
-------------------------------------------(省略)-----------------------------------------------------
Private _commitAnime As Boolean = False
Private Sub StateInvalidated(ByVal sender As Object, ByVal e As EventArgs)
_commitAnime = True
End Sub