ItemsPanel VS网VS GridSplitter [英] ItemsPanel vs Grid vs GridSplitter

查看:102
本文介绍了ItemsPanel VS网VS GridSplitter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在试图建立一个控件模板的使用网格作为其ItemsPanel,其中每个项目是水平堆叠,并划定了GridSplitter一个ItemsControl。

I am currently trying to build a ControlTemplate for an ItemsControl that uses the Grid as its ItemsPanel where each item is stacked horizontally and delimited with a GridSplitter.

其基本目标是有一个动态的绑定ItemsControl中,所有物品堆放在一个行,其中每个项目可以与分路器进行调整。

The basic goal is to have a dynamic bindable ItemsControl where all items stack up in a row and where each item can be resized with a splitter.

有两件事情我不能环绕我的头:在GridSplitter应该怎样自动结束了各项目之间?如何设置Grid.Column为每个项目。

There are two things I can't wrap my head around: How is the GridSplitter supposed to end up automatically between each item? How do I set Grid.Column for each item.

如果这不能用一个简单的控制模板,这将是实现这样的一个共同的好办法呢?我是否需要写这个新的ItemsControl?

If this can't be done with a simple control template what would be a common and good way to implement something like this? Do I need to write a new ItemsControl for this?

我需要实际的(网格)分配器控制所以可自定义CONTROLTEMPLATES他们。此外,我认为它会来的非常方便于对细胞(GridLengthUnitType,拉伸,对齐)的附加布局功能。

I need actual (Grid)Splitter controls so there can be custom ControlTemplates for them. Also I think it would come in quite handy to have the additional layout functionality for the cells (GridLengthUnitType, Stretch, Alignment).

所以滚动的时候,我自己我想我会需要一个自定义的ItemsControl(产生分路器为​​每个项目)和一个自定义面板(其行为类似onerow / onecolumn格 - 因此无需附加Grid.Row,网格.COLUMN性能,.Orientation就足够了),可以采取分流控制,并且知道如何处理他们布点的角度。

So when rolling my own I guess I would need a custom ItemsControl (that generates the splitters for each item) and a custom panel (that behaves like a onerow/onecolumn grid - so no need for the attached Grid.Row, Grid.Column properties, .Orientation would suffice) that can take Splitter controls and knows how to deal with them in terms of layouting.

你怎么想到这个办法的?是preferred还是一个好方法吗?

What do you think of this approach? Is the preferred or a good way?

推荐答案

我的理解是,ItemsControl的是基于每个项目只产生,并增加了一个控制的itemshost的想法。创建既是GridSplitter和每个项目的默认itemcontainer违背这个原则。

My understanding is that the ItemsControl is based on the idea that for each item it only creates and adds one control to the itemshost. Creating both a GridSplitter and the default itemcontainer per item goes against this principle.

因为你只有一列,并只希望垂直调整大小,我建议编写自己的面板,它就像一个StackPanel中,但总会留下的子元素之间的几个像素的差距。如果鼠标移动到这个差距,并且用户开始拖动,面板可以调整大小最接近的子元素。

Since you only have one column, and only want to resize vertically, i'd suggest writing your own panel, which behaves like a StackPanel but always leaves a gap of a few pixels between the child elements. If the mouse is over this gap, and the user begins to drag, the panel can resize the nearest child elements.

所以,调整大小逻辑,就必须在自定义面板上实现,这是想最大的缺点,但IMO非常值得,因为它被藏在只有一个地方。你并不需要在你的ItemsControl / ItemTemplate中/ ItemContainerStyle其他做什么特比使用此面板itemshost。

So the resize logic would have to be implemented on the custom panel., which is think the biggest drawback, but IMO well worth it because it is tucked away in one place only. You don't need to do anything special in your ItemsControl/ItemTemplate/ItemContainerStyle other than use this Panel as itemshost.

您也可以使用标准的StackPanel中添加鼠标处理程序给它的实现调整大小的逻辑。但你不得不在你的ItemContainerStyle创建空白设置保证金。

You could also use a standard StackPanel and add mouse handlers to it which implement the resize logic. But then you'd have to set a margin in your ItemContainerStyle to create the gaps.

这篇关于ItemsPanel VS网VS GridSplitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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