为什么ActualWidth和ActualHeight从0,0开始?
我想将 WPF 路径添加到 InkCanvas
并使用选择来选择 WPF 路径。 所以,我使用这段代码。
System.Windows.Shapes.Path path = drawCanvas.Children[i] as System.Windows.Shapes.Path;
drawCanvas.Children.RemoveAt(i);
inkCanvas.Children.Add(path);
这是输出。我必须从 0,0 选择 WPF 路径,因为 Actualwidth
和 ActualHeight
从 0,0 开始。
如何选择绝对 WPF 路径?
谢谢
编辑:
现在,我可以使用此代码绝对选择它。
System.Windows.Shapes.Path path = drawCanvas.Children[i] as System.Windows.Shapes.Path;
drawCanvas.Children.RemoveAt(i);
path.Margin = new Thickness(-getMinX(path), -getMinY(path), 0, 0);
containPath.Children.Add(path);
containPath.Width = getMaxX(path) - getMinX(path);
containPath.Height = getMaxY(path) - getMinY(path);
containPath.Margin = new Thickness(getMinX(path), getMinY(path), 0, 0);
inkCanvas.Children.Add(containPath);
I want to add WPF Path to InkCanvas
and use selection to select WPF Path.
So, I use this code.
System.Windows.Shapes.Path path = drawCanvas.Children[i] as System.Windows.Shapes.Path;
drawCanvas.Children.RemoveAt(i);
inkCanvas.Children.Add(path);
This is the output. I have to select WPF Path from 0,0 because Actualwidth
and ActualHeight
start from 0,0.
How do I select absolute WPF Path?
Thanks
Edit:
Now, I can select it absolutely by using this code.
System.Windows.Shapes.Path path = drawCanvas.Children[i] as System.Windows.Shapes.Path;
drawCanvas.Children.RemoveAt(i);
path.Margin = new Thickness(-getMinX(path), -getMinY(path), 0, 0);
containPath.Children.Add(path);
containPath.Width = getMaxX(path) - getMinX(path);
containPath.Height = getMaxY(path) - getMinY(path);
containPath.Margin = new Thickness(getMinX(path), getMinY(path), 0, 0);
inkCanvas.Children.Add(containPath);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(2)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以使用 UIElement.UpdateLayout 方法在
InkCanvas
上更新 FrameworkElement.ActualWidth 属性 和ActualHeight
。请参阅ActualWidth
链接,了解为什么需要此功能的背景信息。编辑:
我误解了这个问题。并不是
ActualWidth
和ActualHeight
为零,而是它们的值相对于InkCanvas< 上的
(0, 0)
/代码>。解决这个问题的一个很好的解决方案是将Path
包装在Canvas
中,并使用Margin
定位它,如下所示:其行为如下:
这种方法的缺点是用户必须套索
Canvas
这是一个矩形,而不是任意形状。尽管如此,这比必须套索对象和原点要好得多。You can use the UIElement.UpdateLayout Method on the
InkCanvas
to update the FrameworkElement.ActualWidth Property andActualHeight
. See theActualWidth
link for background information on why this is needed.Edit:
I misunderstood the question. It wasn't that
ActualWidth
andActualHeight
were zero but that their values were relative to(0, 0)
on theInkCanvas
. A pretty good solution to the problem is to wrap thePath
in aCanvas
and position it usingMargin
like this:which behaves like:
The disadvantage of this approach is the user has to lasso the
Canvas
which is a rectangle, not an arbitrary shape. Nevertheless, it's a lot better than having to lasso the object and the origin.