InkCanvas 中的 WPF 绝对定位
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于能弄清楚了。我也觉得自己有点傻需要使用
InkCanvas.SetTop
而不是Canvas.SetTop()
。Finally able to figure out. I feel kinda stupid too. Instead of
Canvas.SetTop()
need to useInkCanvas.SetTop
.