【发布时间】:2012-01-25 09:45:49
【问题描述】:
我正在尝试创建一个具有可变行数和列数的表。我正在使用ItemsControl 执行此操作,Grid 作为其ItemsPanel。我知道我可以通过ItemContainerStyle 设置每个项目的Grid.Row 和Grid.Column。但是当我无法通过名称访问 Grid 时,我不知道如何更改行数和列数及其大小。
问题:
如何在运行时在没有任何代码隐藏的情况下使用绑定修改RowDefinitions 或ColumnDefinitions 的ColumnDefinitions?
这是 XAML 代码:
<ItemsControl Name="myItemsControl" ItemsSource="{Binding Cells}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid Name="myGrid">
<Grid.RowDefinitions>
<!-- unknown number of rows are added here in run-time -->
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<!-- known number of columns are added here in run-time -->
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style.../>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
我尝试在后面的代码中添加一些RowDefinition,但我找不到通过名称(或任何其他方式)访问myGrid 的方法,因为它位于ItemsPanelTemplate 中。
我想知道是否有任何方法可以在运行时以编程方式添加或修改RowDefinitions?
【问题讨论】:
标签: wpf templates grid itemscontrol