【发布时间】:2011-02-22 10:52:57
【问题描述】:
我有一个带有选项卡控件和页数的窗口 - 选项卡项。每个选项卡项具有相同的网格布局 - 6 行和 4 列。现在,每个选项卡项都包含带有行和列定义的网格,因此几乎一半的 XAML 是网格定义。
如何在一个地方定义此网格并在我的应用程序中重复使用该定义?模板?用户控制?
除了 6x4,我只有两个重复的网格尺寸:8x4 和 6x6。
编辑:
忘了提一下:每个选项卡的网格控件都不同。我只想在某些资源中定义一次网格,以便我可以在不同的标签页上重用它们。现在 XAML 看起来像这样:
<TabControl>
<TabItem Header="Property">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!-- some controls here -->
</Grid>
</TabItem>
<TabItem Header="Style">
<Grid >
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!-- some controls here -->
</Grid>
</TabItem>
... and this repeats for several more tab items
</TabControl>
此网格定义对表单上的每个选项卡项重复。让我恼火的是 XAML 的一半是网格定义。
有没有办法在一个地方定义这个网格,然后重复使用这个定义?
【问题讨论】: