代码之家  ›  专栏  ›  技术社区  ›  Mauro Destro

创建六边形网格

  •  12
  • Mauro Destro  · 技术社区  · 17 年前

    我必须这样做一个“网格”:

    Harmonic table Harmonic table

    ListView 具有 ItemsSource="List<Note>" 列表中的每个奇数音符都被移动到底部。。。

    是 列表视图

    我怎样才能画出一个精确的六边形,它的面靠近下一个对象?

    编辑:

    <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"/>
    
    2 回复  |  直到 15 年前
        1
  •  7
  •   Mart    15 年前

    你笔记的容器应该是一个 ItemsControl 或者 ListBox 如果您需要选择项目。然后使用 ListBox.ItemTemplate Custom ListBox layout .

    此时,您的六边形将一个接一个地显示,默认情况下列表框就是这样。要获得您的特殊布局,您必须更改 ListBox.ItemPanel . 这里有两种可能性:

    • Canvas 支持绝对定位的面板。在这种情况下,项目必须具有用于定位它们的X和Y属性。
    • Panel ,可能基于 ,它能够将自定义坐标系(例如注释名称+倍频程数)转换为X和Y。这有点困难,但更易于重用。一个例子 Custom Panel on CodeProject
        2
  •  2
  •   ASh aminescm    9 年前

    HexGrid: CodeProject article

    HexGrid: GitHub repository

    可能的解决方案的关键组件是WPF面板,它可以排列六边形元素(标准面板使用矩形子元素)。看看我的HexGrid项目(太大,无法在此处发布)。它的中心部分是一个 HexGrid Panel 它以蜂窝状模式排列子元素)。子元素由 HexItem s(六边形控件)。还有 HexList (selector items控件,它在HexGrid面板上显示HexItem容器中的项目),它提供了开箱即用的十六进制选择支持。

    <hx:HexList Name="HexColors" Orientation="Vertical"
                Grid.Row="1"
                Padding="10"
                SelectedIndex="0"
                Background="{Binding Path=SelectedItem.Background, RelativeSource={RelativeSource Self}}"
                RowCount="5" ColumnCount="5">
        <hx:HexItem Grid.Row="0" Grid.Column="1" Background="#006699"/>
        <hx:HexItem Grid.Row="0" Grid.Column="2" Background="#0033CC"/>
        <hx:HexItem Grid.Row="0" Grid.Column="3" Background="#3333FF"/>
        <!--...-->
        <hx:HexItem Grid.Row="4" Grid.Column="1" Background="#CC9900"/>
        <hx:HexItem Grid.Row="4" Grid.Column="2" Background="#FF3300"/>
        <hx:HexItem Grid.Row="4" Grid.Column="3" Background="#CC0000"/>
    </hx:HexList>
    

    hex color selector