在 Silverlight 中以编程方式设置 TranslateX 或 Canvas.SetLeft 属性

发布于 2024-08-28 04:18:50 字数 300 浏览 3 评论 0原文

所以问题是,我试图让那个圆圈与数字对齐。当我在混合中执行此操作时,它显示我有一个 Left (23),我尝试以编程方式执行此操作 Canvas.SetLeft(thePanel,23) 它会超出。更好的是,如果有人知道 silverlight 中有这样的控件,请告诉我。其作用是,当用户单击一个数字时,绿色圆圈会转到该数字,因此看起来用户已选择它。 alt 文本

混合

So Here is the Problem, I am trying to get that circle to align on the number. When I do that in blend it shows me I have a Left (23), I try to do that programmaticly Canvas.SetLeft(thePanel,23) it overshoots. Better yet, if anyone knows of a control like this in silverlight let me know. What this does is when the user clicks on a number the green circle is suppose to go to that number so it looks like the user has selected it. alt text

Blend

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒带 2024-09-04 04:19:02

在 Circle 对象上,您必须设置圆的 Radius 和 TranslateTransform 属性。假设您的圆的半径为 15:

private const double Radious = 15.0;

private double _x = Radious;
private double _y = Radious;

private TranslateTransform _translation = new TranslateTransform();

以及处理圆的 X 和 Y 坐标的属性,

public double X
    {
        get { return this._x; }
        set
        {
            this._x = value;
            _translation.X = this._x - Radious;
        }
    }

    public double Y
    {
        get { return this._y; }
        set
        {
            this._y = value;
            _translation.Y = this._y - Radious;
        }
    }

在 Silverlight 中,您可以获取用户在画布上单击的位置,在面板的单击事件上设置此代码,然后设置圆心到用户单击的位置:

//Get the points where it was clicked
Point clickPoint = e.GetPosition(Canvas);

MyCircle.X = clickPoint.X;
MyCircle.Y = clickPoint.Y;

现在,如果您希望它们始终落在固定位置,您可以设置条件,如果用户单击某个数字,则将圆心设置为该数字的中心数字,或者只是更改圆的 X 值以移动到所需的位置。

On your Circle object you have to set the Radius of the circle and the TranslateTransform attribute. Lets say your Circle has a radius of 15:

private const double Radious = 15.0;

private double _x = Radious;
private double _y = Radious;

private TranslateTransform _translation = new TranslateTransform();

and properties to handle the Circle's X and Y coordinates,

public double X
    {
        get { return this._x; }
        set
        {
            this._x = value;
            _translation.X = this._x - Radious;
        }
    }

    public double Y
    {
        get { return this._y; }
        set
        {
            this._y = value;
            _translation.Y = this._y - Radious;
        }
    }

and in Silverlight you can get where the user has clicked on a Canvas, setting this code on the Click Event of the panel, and set the center of the circle to where the user has clicked:

//Get the points where it was clicked
Point clickPoint = e.GetPosition(Canvas);

MyCircle.X = clickPoint.X;
MyCircle.Y = clickPoint.Y;

Now, if you want them to always fall in fixed positions, you can set conditions that, if a user clicks around a number, then set the center of the circle to the center of the number, or just change the X value of your circle to move to the desired position.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文