【发布时间】:2016-10-27 17:59:25
【问题描述】:
我正在通过 WPF 构建一个网格,效果很好。我需要在网格上方添加一行或条形或显示的内容,上面将有几个文本项,这些文本项将由代码填充。我一直在使用工具,但我似乎无法弄清楚如何将另一个面板放在我现有的(和工作的)网格之上。这是我的代码:
<Window x:Class="GridWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Board" SizeToContent="WidthAndHeight" Height="Auto" Width="Auto">
<Window.Resources>
<DataTemplate x:Key="DataTemplate_2">
<Button Content="{Binding}" Height="25" Width="25" Margin="0,0,0,0"/>
</DataTemplate>
<DataTemplate x:Key="DataTemplate_1">
<ItemsControl ItemsSource="{Binding}" ItemTemplate="{DynamicResource DataTemplate_2}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
</Window.Resources>
<Grid Name="GridBoard" ShowGridLines="True">
<ItemsControl x:Name="GridItems" ItemTemplate="{DynamicResource DataTemplate_1}"/>
</Grid>
</Window>
GridItems 由一个锯齿状数组填充,并且显示良好。我只需要在其上方放置一些文本对象,无论是框,还是适合网格宽度的水平面板。
【问题讨论】: