创建六边形网格
我必须做一个像这样的“网格”:
我正在尝试创建一个 ListView< /code> 与
ItemsSource="List
列表中的每个奇怪的注释都移动到底部...
ListView
是正确的控件吗?
如何绘制一个精确的六边形,其面靠近下一个对象?
编辑:六边形绘制已解决...这是xaml:
<Path d:LayoutOverrides="None"
d:LastTangent="0,0" Stroke="Blue" Fill="Red"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Margin="0" Width="100" Height="100" x:Name="Path"
Stretch="Fill"
Data="M8.660254,0 L17.320508,5 17.320508,15 8.660254,20 0,15 0,5 8.660254,0 z"/>
I have to do a "grid" like this:
I'm trying to create a ListView
with ItemsSource="List<Note>"
where every odd note in the list is moved on the bottom...
Is the ListView
the right control?
How can I draw an exact hexagon with faces that is near next object?
EDIT: hexagon drawing is solved... this is the xaml:
<Path d:LayoutOverrides="None"
d:LastTangent="0,0" Stroke="Blue" Fill="Red"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Margin="0" Width="100" Height="100" x:Name="Path"
Stretch="Fill"
Data="M8.660254,0 L17.320508,5 17.320508,15 8.660254,20 0,15 0,5 8.660254,0 z"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您需要选择项目,则注释的容器将是
ItemsControl
或ListBox
。然后,您使用ListBox.ItemTemplate
为您的项目提供一个模板,其中包含您的六边形绘图。您有一个关于自定义列表框布局的很好的教程。此时,您的六边形将像列表框默认情况下一样显示在另一个下方。要获得特殊布局,您必须更改
ListBox.ItemPanel
。这里有两种可能性:Canvas
面板。在这种情况下,您的项目必须具有用于定位它们的 X 和 Y 属性。Panel
,可能基于Canvas
,它能够将您的自定义坐标系(例如音符名称+八度音阶数)转换为X和Y。有点困难,但更可重用。 CodeProject 上的自定义面板的示例。The container for your notes would be an
ItemsControl
or aListBox
if you need to select items. Then you give your items a template usingListBox.ItemTemplate
where you include your hexagon drawing. You have a nice tutorial on Custom ListBox layout.At this point, your hexagons are displayed one below the other as a ListBox does by default. To get your special layout, you have to change the
ListBox.ItemPanel
. Here you have two possibilities:Canvas
panel that supports absolute positioning. In this case your items must have X and Y properties that you will use to position them.Panel
, probably based onCanvas
, that is able to convert your custom coordinate system (for example note name + octave number) into X and Y. A bit more difficult but much more reusable. An example of Custom Panel on CodeProject.HexGrid:CodeProject 文章
HexGrid:GitHub 存储库
可能解决方案的关键组件是可以排列六边形元素的 WPF 面板(标准面板使用矩形子元素进行操作)。看一下我的 HexGrid 项目(太大,无法在此处发布)。它的中心部分是一个
HexGrid
(WPFPanel
,它以蜂窝状图案排列子元素)。子元素由HexItem
(六边形内容控件)表示。还有HexList
(选择器 ItemsControl,它在 HexGrid 面板上显示 HexItem 容器中的项目),它提供开箱即用的十六进制选择支持。使用示例:
HexGrid: CodeProject article
HexGrid: GitHub repository
The key component of a possible solution is a WPF Panel which can arrange hexagonal elements (Standard Panels operate with rectangular child elements). Take a look my HexGrid project (too large to post here). The cental part of it is a
HexGrid
(WPFPanel
which arranges child elements in a honeycomb pattern). Child elements are represented byHexItem
s (hexagon-shaped ContentControls). There is alsoHexList
(selector ItemsControl which displays items in HexItem container on a HexGrid panel) which gives hex selection support out-of-box.example of usage: