创建六边形网格 [英] Creating grid of hexagons

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

问题描述

我必须做一个网格是这样的:


谐波表

我试图创建一个的ListView 的ItemsSource =列出<注意>中,其中每个奇数音符在列表上移动的底部...

的ListView 右侧控制?

如何绘制的面孔一个确切的六边形是接近下一个对象?

编辑:六角绘图解决......这是XAML:

 <路径D:LayoutOverrides =无
      D:LastTangent =0,0行程=蓝填充=红
      的Horizo​​ntalAlignment =拉伸VerticalAlignment =弹力
      保证金=0WIDTH =100HEIGHT =100X:NAME =路径
  拉伸=填充
      数据=M8.660254,0 L17.320508,5 17.320508,15 8.660254,20 0,15 0,5 8.660254,0 Z/>


解决方案

为您的笔记容器将是的ItemsControl 的ListBox 如果您需要选择项目。然后,你给你的项目使用 ListBox.ItemTemplate ,您包括您六边形的绘图模板。您对自定义列表框布局一个很好的教程。

在这一点上,你的六边形显示以下任一其他作为列表框的默认操作。为了让您的特殊布局,则必须更改 ListBox.ItemPanel 。这里有两种可能性:


  • 无论您使用支持绝对定位的画布面板。在这种情况下,您的项目必须有X和Y的属性,您将使用放置它们。

  • 或你创建一个自定义面板,可能是基于画布,即能转换您的自定义坐标系(例如音符名称+倍频数)为X和Y有点难度,但更多的重用。 自定义面板上$ C $的CProject 的一个例子。

I have to do a "grid" like this:

Harmonic table

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"/>

解决方案

The container for your notes would be an ItemsControl or a ListBox if you need to select items. Then you give your items a template using ListBox.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:

  • either you use the Canvas panel that supports absolute positioning. In this case your items must have X and Y properties that you will use to position them.
  • or you create a custom Panel, probably based on Canvas, 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.

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

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