这是一个使用 UniformGrid 的示例,它可能接近您想要实现的目标。
XAML
<Grid>
<ListBox ItemsSource="{Binding GridItemsList}" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="2" Columns="4" FlowDirection="RightToLeft" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding ItemName}" />
<StackPanel.LayoutTransform>
<RotateTransform Angle="-90"/>
</StackPanel.LayoutTransform>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.LayoutTransform>
<RotateTransform Angle="-90"/>
</ListBox.LayoutTransform>
</ListBox>
</Grid>
代码背后
public partial class UniformGridWindow : Window {
public UniformGridWindow() {
//Sample Data
GridItemsList = new List<GridItem> {
new GridItem("Item 1"),
new GridItem("Item 2"),
new GridItem("Item 3"),
new GridItem("Item 4"),
new GridItem("Item 5"),
new GridItem("Item 6"),
new GridItem("Item 7"),
new GridItem("Item 8")
};
InitializeComponent();
this.DataContext = this;
}
public List<GridItem> GridItemsList { get; set; }
}
public class GridItem {
public string ItemName { get; set; }
public GridItem(string itemName) {
this.ItemName = itemName;
}
}