如何防止Rectangle被剪裁为网格大小 [英] How do I prevent Rectangle from being clipped to Grid Size

查看:81
本文介绍了如何防止Rectangle被剪裁为网格大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮忙!如果我能弄清楚这一点,我想我在家是免费的。我正在构建一个操作几个矩形的自定义触摸控件。矩形需要大于网格大小才能使控件有用。由于某种原因,矩形被剪裁为网格大小。我真的需要Grid不将Shape剪辑到它的边界,所以当它被拖动时它是全尺寸的。如果矩形在Grid界限之外不可见,那将是很好的,但不是必需的。



让我知道是否有任何我可以添加以使此问题清楚。



谢谢!



以下是一些代码片段:

< br $>
MAIN WINDOW

PLEASE help! If I can figure this out I think I am home free. I am building a custom touch control that manipulates a couple Rectangles. The Rectangles need to be larger than the Grid size for the control to be useful. For some reason the rectangle is being clipped to the grid size. I really need the Grid to not clip the Shape to its bounds so when it is dragged around it is full size. It would be nice if the rectangle was not visible beyond the Grid bounds, but not required.

Let me know if there is anything I can add to make this issue clear.

Thanks!

Here are some code snippets:

MAIN WINDOW

<Grid>

    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="500" />
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="500" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="500" />
    </Grid.ColumnDefinitions>

    <RCL:RectangleControl x:Name="RectControl" Grid.Row="1" Grid.Column="1" />

</Grid>





USER CONTROL



USER CONTROL

<Grid ClipToBounds="False" >
 <Grid x:Name="MainCanvas" ClipToBounds="False" Width="501" Height="501">
  <Rectangle  x:Name="1A_Rectangle" 

              HorizontalAlignment="Center" VerticalAlignment="Center" 

              Width="350" Height="750" 

              RenderTransformOrigin="0.5, 0.5" 

              IsManipulationEnabled="True"  

              Fill="Red" />

  <Rectangle  x:Name="1B_Rectangle" 

              Width="350" Height="750"

              HorizontalAlignment="Center" VerticalAlignment="Center"

              RenderTransformOrigin="0.5, 0.5"  

              IsManipulationEnabled="True"  Fill="Blue" Stroke="#FF707070"   />
 </Grid>          
</Grid> 

推荐答案

您好,

我想你可以阅读以下关于剪辑如何在WPF中工作的文章: http://blogs.msdn.com/b/jaimer/archive/2006/08/10/695069.aspx [ ^ ]



<罢工>我认为您可以尝试创建无法删除的矩形,就像文章一样,稍后您在控件中使用。



代码可能如下所示:

Hello,
I think you could read the following article about how clipping works in WPF: http://blogs.msdn.com/b/jaimer/archive/2006/08/10/695069.aspx[^]

I think you can try creating "unclippable" rectangles, like in the article, that later you use in your control.

The code might look like this:

public class UCRectangle : Rectangle
{
  protected override Geometry GetLayoutClip ( Size ls )
  {
  return null;
  }
}





我的第二个想法是,相反使用rendertransform你可以通过改变它们来移动你的矩形利润率。在这种情况下,裁剪有助于将控件保持在网格单元格中,因此在视觉上它应该是,你想要实现的目标。



玩了一下之后,这就是看起来的样子工作:

向上移动矩形120像素:



My second thought is, that instead using rendertransform you might move your rectangles by changing their margins. In this case clipping would help keeping the control within grid cells, so visually it should be, what you want achieve.

After playing around a bit, this is what seems working:
Moving the rectangle upwards by 120 pixels:

<Rectangle Margin="0 -120 0 0" ... />



将矩形向下移动120像素:


Moving the rectangle downwards by 120 pixels:

<Rectangle Margin="0 0 0 -120" ... />



但是,这应该比rendertransform慢,因为我们改变了组件的布局,即使我们只移动一个矩形。 />




我最后的猜测是,你可以用Canvas控件替换名为MainCanvas的Grid,而Canvas.Top会移动Rectangles ,Canvas.Left属性。



更新: Upps,我忘了,Rectangle是一个密封的类,所以也许边缘是我最好的猜测。抱歉我的错误。


However, this should be slower than the rendertransform, because we change the layout of the components, even though we are moving just one rectangle.


My final guess is, that you could replace the Grid called "MainCanvas" with Canvas control and Rectangles would be moved by the Canvas.Top, Canvas.Left properties.

Update: Upps, I forgot, that Rectangle is a sealed class, so maybe the margins are my best guess. Sorry about my mistake.


这篇关于如何防止Rectangle被剪裁为网格大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆