I have a mainview with a grid divided into two columns.
The issue is that I have an organized list of view models ( user controls with a textbox with different scopes ) that is created dynamically, and I want to display them in a Z way. I.e: from left to right, top to bottom ( see image )
At the moment i'm using something like the code above, dividing the list in the viewmodel into two different lists according to the element index.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Stackpanel Grid.Column=0>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="EvenElements">
<Border>
<TextBlock Text="{Binding}" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</Stackpanel>
<Stackpanel Grid.Column=1>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="OddElements">
<Border>
<TextBlock Text="{Binding}" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</Stackpanel>
</Grid>
Is there a way to do it in a single binding style? I don't want to join the textboxes input later because the index matters, and the code doesn't look that clean in that way. Thank you
If I understand your issue correctly, you could use an UniformGrid as the ItemsPanel of the ItemsControl:
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="2" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>