0

私は Windows Phone アプリに取り組んでおり、画像の位置を変更するストーリーボードを作成していますが、エラーがあります。

タイプ 'System.InvalidOperationException' の例外が System.Windows.ni.dll で発生しましたが、ユーザー コード ストーリーボードでは処理されませんでした

これは私のコードです:

XAML:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" MouseMove="Mouse_Move">
    <Grid.Resources>
        <Storyboard x:Name="sbimg">
            <PointAnimation x:Name="animationimg" Duration="0:0:0.1"
                    Storyboard.TargetName="earimg" />
        </Storyboard>
    </Grid.Resources>                    
    <Image x:Name="earimg" Height="30" Width="30"
        Source="1.png" Margin="0,0,426,577">
    </Image>             
</Grid>

そしてC#:

private void Mouse_Move(object sender, System.Windows.Input.MouseEventArgs e)
{
    double pointX = e.GetPosition(null).X;
    double pointY = e.GetPosition(null).Y;            
    Point mypoint = new Point(pointX,pointY);
    animationimg.To = mypoint;
    sbimg.Begin();
}
4

1 に答える 1

0

このタスクを達成するには、CanvasasLayoutRootGestureListnerfromを使用しWindows Phone Toolkitてユーザーのジェスチャーをキャッチすることをお勧めします。あなたXAMLはこのように見えるはずです

 <Canvas x:Name="LayoutRoot" 
            Background="Transparent">
        <toolkit:GestureService.GestureListener>
            <toolkit:GestureListener
                    x:Name="SurfaceGestureListner"
                     Tap="SurfaceGestureListner_OnTap"
                    DragDelta="GestureListnerDragDelta"/>
        </toolkit:GestureService.GestureListener>
        <Image 
            x:Name="MyImage"
            Source="/Assets/ApplicationIcon.png" Height="100" Width="100">
            <Image.RenderTransform>
                <TranslateTransform x:Name="TranslateTransform"/>
            </Image.RenderTransform>
         </Image>
    </Canvas>

そしてコードビハインドで

 private Storyboard GenerateMoveAnimation(double x, double y)
        {
            var xAnimation = new DoubleAnimation
                                 {
                                     From = TranslateTransform.X,
                                     To = x
                                 };

            var yAnimation = new DoubleAnimation
                                 {
                                     From = TranslateTransform.Y,
                                     To = y
                                 };

            Storyboard.SetTarget(xAnimation, TranslateTransform);
            Storyboard.SetTargetProperty(xAnimation, new PropertyPath("X"));

            Storyboard.SetTarget(yAnimation, TranslateTransform);
            Storyboard.SetTargetProperty(yAnimation, new PropertyPath("Y"));

            var str = new Storyboard();
            str.Children.Add(xAnimation);
            str.Children.Add(yAnimation);

            return str;
        }

        private void GestureListnerDragDelta(object sender, DragDeltaGestureEventArgs e)
        {
            var point = e.GetPosition(LayoutRoot);
            GenerateMoveAnimation(point.X, point.Y).Begin();
        }

        private void SurfaceGestureListner_OnTap(object sender, Microsoft.Phone.Controls.GestureEventArgs e)
        {
            var point = e.GetPosition(LayoutRoot);
            GenerateMoveAnimation(point.X, point.Y).Begin();            
        }
于 2013-06-11T17:31:23.120 に答える