[英]WPF cut controls that goes outside the grid
I'm learning C# and WPF. 我正在学习C#和WPF。 I need to put a form with some
Image
on a face of a 3D cube (the cube is defined in a Viewport3D
) using the Viewport3DVisual3D
control. 我需要使用
Viewport3DVisual3D
控件在3D多维数据集(多维数据集在Viewport3D
定义)的表面上放置带有一些Image
的表单。
I defined the Visual
element of the Viewport3DVisual3D
as a Grid
. 我将
Viewport3DVisual3D
的Visual
元素定义为Grid
。 I defined the grid dimensions equal to the dimension of the cube's face. 我定义的网格尺寸等于立方体面的尺寸。 I added the images as children of the grid:
我将图像添加为网格的子代:
How can I position the images to the desired (x,y) on the grid? 如何将图像定位到网格上的所需(x,y)? I tried with the
Margin
propriety of the Image
, as example: 我尝试使用
Image
的Margin
适当性,例如:
Image im = new Image();
im.Source = new BitmapImage(new Uri("panotec.png"));
im.Width = 0.5;
im.Margin = new Thickness(-6, -0.5, 0, 0);
But when the image goes out form the area defined by the grid dymension the whole grid is compressed to fit the cube's face surface. 但是,当图像从网格尺寸定义的区域出来时,整个网格将被压缩以适合立方体的表面。 as in the image:
如图所示:
How can I prevent it? 我该如何预防? I want that the parts of the controls that are outside just being cropped.
我希望外面的控件部分被裁剪掉。 Is it possible?
可能吗?
Thanks in advance. 提前致谢。
The answer is really simple: 答案很简单:
myGrid.ClipToBounds = true;
Also moved from Grid
to Canvas
for better position the images: 还从
Grid
移动到Canvas
以更好地定位图像:
Canvas myCanvas = new Canvas();
Image im = new Image(...);
Canvas.SetTop(im, top);
Canvas.SetLeft(im, left);
myCanvas.Children.Add(im);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.