Search code examples
wpfbindingcode-behind

WPF: Create 8x8 TextBox table in codebehind


I need to create 8x8 TextBox table, each TextBox should be bound to element of double[,] array (i want to let user change matrix from ui).

What is the most elegant way to do this?


Solution

  • I would use an ItemsControl, and change the ItemPanel from the default StackPanel to a WrapPanel. Something like:

    <ItemsControl>
      <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
              <WrapPanel />
          </ItemsPanelTemplate>
      </ItemsControl.ItemsPanel>
      <ItemsControl.ItemTemplate>
          <DataTemplate>
            ...
          </DataTemplate>
      </ItemsControl.ItemTemplate>
    </ItemsControl>