У меня есть WPF TextBlock
. Я контролирую размер шрифта с помощью ManipulationDelta
, чтобы имитировать увеличение / уменьшение масштаба. В настоящее время это очень грубый способ, но он работает.
Это работает для сенсорного экрана, но я хочу, чтобы такое же поведение работало на сенсорной панели моего ноутбука - т.е. масштабирование двумя пальцами.
К какому событию я должен подключиться, чтобы сделать эту работу?
Код касания следующий:
<TextBlock Name="txbl_displaySong" Foreground="White" FontFamily="Lucida Console"
FontSize="22" Text="{Binding Path=T.SelectedSong.TransposedChordsOverLyrics, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
Padding="20" TextWrapping="Wrap" IsManipulationEnabled="True"
ManipulationDelta="txbl_displaySong_ManipulationDelta"
ManipulationCompleted="Txbl_displaySong_ManipulationCompleted"
TouchDown="Txbl_displaySong_TouchDown"
MouseDown="Txbl_displaySong_MouseDown"/>
Код сзади:
Dim isPinchIn As Boolean = False
Dim isPinchOut As Boolean = False
Dim prevScale As Double = 0
Private Sub Txbl_displaySong_ManipulationCompleted(sender As Object, e As ManipulationCompletedEventArgs)
prevScale = 0
isPinchIn = False
isPinchOut = False
End Sub
Private Sub txbl_displaySong_ManipulationDelta(sender As Object, e As ManipulationDeltaEventArgs)
Dim tScale As Double = e.CumulativeManipulation.Scale.Length
If (prevScale > 0) Then
isPinchIn = isPinchIn OrElse prevScale > tScale ' if same scale, assume no change
isPinchOut = isPinchOut OrElse prevScale < tScale ' if same scale, assume no change
End If
prevScale = tScale
Dim mCount As Integer = e.Manipulators.Count
...
If mCount = 2 Then
If isPinchIn Then
txbl_displaySong.FontSize = Math.Max(6.0, txbl_displaySong.FontSize - 0.2) ' limit to 6
ElseIf isPinchOut Then
txbl_displaySong.FontSize = Math.Min(40.0, txbl_displaySong.FontSize + 0.2) ' limit to 40
Else
End If
End If
End Sub
...