InkCanvas 中的 WPF 绝对定位

发布于 2024-08-03 21:45:29 字数 796 浏览 5 评论 0原文

我正在尝试在 InkCanvas 中放置一个矩形。我正在使用以下方法。不幸的是,当我添加矩形时,它会显示在 (0,0) 处。尽管当我查询 left 属性是否为 0 时,我得到一个非零值。有谁知道为什么会这样?

干杯,

尼禄

InkCanvas _parent = new InkCanvas();
private void AddDisplayRect(Color annoColour, Rect bounds)
    {
        Rectangle displayRect = new Rectangle();
        Canvas.SetTop(displayRect, bounds.Y);
        Canvas.SetLeft(displayRect, bounds.X);

        // check to see if the property is set
        Trace.WriteLine(Canvas.GetLeft(displayRect));
        displayRect.Width = bounds.Width;
        displayRect.Height = bounds.Height;
        displayRect.Stroke = new SolidColorBrush(annoColour);
        displayRect.StrokeThickness = 1;

        _parent.Children.Add(displayRect);            
    }

I'm trying to position a rectangle in an InkCanvas. I am using the following method. Unfortunately when I add the rectangle it gets displayed at (0,0). Although when I query to see the whether the left property is 0 I get a non zero values. Does anyone know why this might be?

Cheers,

Nilu

InkCanvas _parent = new InkCanvas();
private void AddDisplayRect(Color annoColour, Rect bounds)
    {
        Rectangle displayRect = new Rectangle();
        Canvas.SetTop(displayRect, bounds.Y);
        Canvas.SetLeft(displayRect, bounds.X);

        // check to see if the property is set
        Trace.WriteLine(Canvas.GetLeft(displayRect));
        displayRect.Width = bounds.Width;
        displayRect.Height = bounds.Height;
        displayRect.Stroke = new SolidColorBrush(annoColour);
        displayRect.StrokeThickness = 1;

        _parent.Children.Add(displayRect);            
    }

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

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

发布评论

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

评论(1

再见回来 2024-08-10 21:45:29

终于能弄清楚了。我也觉得自己有点傻需要使用 InkCanvas.SetTop 而不是 Canvas.SetTop()

Finally able to figure out. I feel kinda stupid too. Instead of Canvas.SetTop() need to use InkCanvas.SetTop.

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