直接儿童的样式

问题描述

鉴于此示例 XAML:

<TabControl>
    <TabItem Header="Test">
        <Grid> <!-- outer grid that should receive the styles -->
            <Grid.RowDefinitions><!-- ... --></Grid.RowDefinitions>
            <Grid.ColumnDefinitions><!-- ... --></Grid.ColumnDefinitions>
            <Grid Grid.Row="1" Grid.Column="1">
                <!-- inner grid,should NOT receive the styles -->
            </Grid>
        </Grid>
    </TabItem>
</TabControl>

如何为 Grid 的所有直接 TabItem 子项设置样式,并且在层次结构中没有其他 Grid 的更深层次?

这是我尝试过的(我把它放在 App.xml 中):

<Style TargetType="TabItem">
    <Style.Resources>
        <Style TargetType="Grid">
            <Setter Property="Margin" Value="10" />
        </Style>
    </Style.Resources>
</Style>

(我知道我可以使用 Style={StaticResource ...} 分配某些样式,但我必须将它单独应用于所有 Grid,这似乎有很多不必要的代码......)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)