【发布时间】:2011-12-17 17:17:37
【问题描述】:
我有用于显示数独游戏网格的自定义项目控件。我希望它将其项目显示为 9X9 网格。每个项目都有 X 和 Y 属性,我想绑定到网格中的该属性位置(网格行和网格。列)。除了绑定这些 grid.row 和 grid.column 属性外,一切看起来都正常。代码如下。这不是绑定的错,因为如果我使用硬值,什么都不会改变。请帮忙:
<ItemsControl Margin="4" ItemsSource="{Binding Cells, Mode=OneWay}" x:Name="grid">
<ItemsControl.ItemTemplate>
<DataTemplate>
<grid:GridCell Grid.Column="{Binding X}" Grid.Row="{Binding Y}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid IsItemsHost="True" Background="Pink">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition Height="2" />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition Height="2" />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="2" />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="2" />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
编辑: 如果我使用例如,没有任何变化
<ItemsControl.ItemTemplate>
<DataTemplate>
<grid:GridCell Grid.Column="2" Grid.Row="2" />
</DataTemplate>
</ItemsControl.ItemTemplate>
【问题讨论】:
标签: c# .net wpf xaml data-binding