我正在尝试实现一个在运行时创建的布局。
布局将分为2,3,4,...
例如,有一个包含1个图像的Big Box。
如果我拖放一张图片,它将被一分为二。
像A => A | B or B | A一样
如果我拖放另一个图像,它将是
A | | B
A | B => --| B or A | --
C | | C简单的提示会更好。
发布于 2013-09-10 16:54:36
这个想法到目前为止很简单。让我们把这一点说清楚。首先,假设根堆栈面板是A,它将是Orientation="Horizontal",如下所示:
StackPanel A = new StackPanel();
A.Width = 300;
A.Height = 200;
A.Background = new SolidColorBrush(Colors.LightBlue);
A.Orientation = Orientation.Horizontal;一旦我们有了A,我们就知道它是根,每当我们添加一些东西到它的时候,它就会把它放在右边,这当然是你想要的A|B或更多的A|B| C。现在当你拖放一个图像检查-
图像的坐标,以检测它悬停在哪个父布局上,然后检查它是否是StackPanel(if(theLayout is StackPanel))
现在检查堆叠面板的方向是什么。[PseudoCode]-
if(Horizontal)
{
//Create a stackpanel with Vertical Orientation and place the image inside it
//stackpanel_with_v_orientation.Children.Add(yourImage)
//then add this stackpanel to theLayout like theLayout.Children.Add(stackpanel_with_v_orientation);
}
else
{
//its over some sub panels,which are ofcourse with vertical
//orientation.just add this up.
}就像这样!让我知道它是否有意义。
发布于 2013-09-10 16:55:08
您可以使用DockPanel或WrapPanel。如果这还不够,您可以实现自己的Panel逻辑,指定项目应该如何排列。不管怎样,看看this link吧。
发布于 2013-09-10 17:10:05
最后,您需要一个如下所示的停靠控件:http://avalondock.codeplex.com/
https://stackoverflow.com/questions/18714221
复制相似问题