ユーザーがどこにでも持ち込めるテキストブロックをキャンバスに追加していますが、テキストブロックを拡大または回転できるようにする方法を見つけようとして立ち往生しています。
//create the textblock
TextBlock txt = new TextBlock() { Text = UserString, FontSize = 56 };
//Adding gesture listener here
GestureListener TextGestureListener = GestureService.GetGestureListener(txt);
txt.MouseEnter += txt_MouseEnter;
TextGestureListener.DragStarted += new EventHandler<DragStartedGestureEventArgs>(GestureListener_DragStarted);
TextGestureListener.DragDelta += new EventHandler<DragDeltaGestureEventArgs>(GestureListener_DragDelta);
TextGestureListener.DragCompleted += new EventHandler<DragCompletedGestureEventArgs>(GestureListener_DragCompleted);
TextGestureListener.PinchDelta += new EventHandler<PinchGestureEventArgs>(GestureListener_PinchDelta);
WholePicture.Children.Add(txt);
//pinch to zoom or at least try!
void GestureListener_PinchDelta(object sender, PinchGestureEventArgs e)
{
TextBlock txt = (TextBlock)sender;
Scale = (ScaleTransform)txt.RenderTransform;
Scale.ScaleX = e.DistanceRatio;
Scale.ScaleY = e.DistanceRatio;
}
ここで、テキストブロックを拡大しようとすると、このエラーでクラッシュするだけです
$exception {System.InvalidCastException: Unable to cast object of type 'System.Windows.Media.TranslateTransform' to type 'System.Windows.Media.ScaleTransform'.
at CrazyFill.Pages.CrazyFillCore.GestureListener_PinchDelta(Object sender, PinchGestureEventArgs e)
at Microsoft.Phone.Controls.SafeRaise.Raise[T](EventHandler`1 eventToRaise, Object sender, GetEventArgs`1 getEventArgs)
at Microsoft.Phone.Controls.GestureListener.RaiseGestureEvent[T](Func`2 eventGetter, Func`1 argsGetter, Boolean releaseMouseCapture)
at Microsoft.Phone.Controls.GestureListener.ProcessTouchPanelEvents()
at Microsoft.Phone.Controls.GestureListener.TouchDelta()
at Microsoft.Phone.Controls.GestureListener.OnTouchFrameReported(Object sender, TouchFrameEventArgs e)
at System.Windows.Input.Touch.OnTouch(Object sender, TouchFrameEventArgs e)
at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)} System.Exception {System.InvalidCastException}