【问题标题】:How to give the x y position to image control at runtime in windows phone 7?如何在 Windows Phone 7 运行时将 x y 位置赋予图像控制?
【发布时间】:2013-04-18 17:28:25
【问题描述】:

我已经在背景中设置了画布并添加了一些图像片段作为该背景画布的子元素,现在我想将特定的图像控件移动到背景画布的给定 x y 位置,所以我尝试了下面给出的这种代码

bg_Canvas.Children[it].RenderTransform = new TranslateTransform();

            TranslateTransform trans = bg_Canvas.Children[it].RenderTransform as TranslateTransform;
            DoubleAnimation animation = new DoubleAnimation();

            animation.To = 80; 
            Storyboard.SetTarget(animation, trans);
            Storyboard.SetTargetProperty(animation, new PropertyPath(TranslateTransform.XProperty));

            Storyboard story = new Storyboard();
            story.Children.Add(animation);


            story.Begin();

它正在工作,但问题是移动图像控件无法放置在背景画布的正确 x 位置,它一直在从放置图像的位置获取 x 位置,实际上第 0 个 x 位置从放置在画布上的图像控件开始,所以我需要设置背景画布的 x 位置以放置图像控件。如果有人知道,我该如何解决这个问题,请告诉我解决方案。

【问题讨论】:

    标签: windows-phone-7 translate-animation


    【解决方案1】:

    不使用翻译,只需告诉画布放置图像的位置:

    Canvas.SetTop(image, 80);
    Canvas.SetLeft(image, 160);
    

    编辑:为了让您为元素设置动画,您可以阅读有关 Storyboard 的信息 - 当您使用它时,在要设置动画的属性中适当地输入 "(Canvas.Left)""(Canvas.Top)"

    如果您使用的是 WP8,您可以修改发布在in this series of posts 的代码以在 Windows Phone 上工作(它是为 Windows 8 编码的)。它使制作动画(包括在画布上)变得非常容易。

    【讨论】:

    • 感谢您的回复,我想将每个图像块移动到背景画布的给定 x y 位置。应该做搬家操作,请告诉我解决办法。
    • 每张图片的移动都需要在特定的时间一个一个的完成,怎么做呢?
    • 编辑并添加了您需要查找的信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    相关资源
    最近更新 更多