有没有办法在
WPF中指定这样的东西:
CSS:
- #someSpan input { color: #f1f1f1; }
- or
- span input { color: #f1f1f1; }
意思是,我希望容器中的所有TextBlock元素都遵循x样式,而不必将样式应用于每个文本块.
为了澄清,我需要在WPF中做这样的事情.
我知道一个样式的BasedOn属性..但这不是我在这里寻找的东西
寻找这样的东西
- <Style x:Key="FileItem" TargetType="{x:Type #SomeContainer TextBlock}">
或者也许在SomeContainer中,添加将应用于其所有文本块的TextBlock样式
解决方法
关于问题的最后一部分,如果要将样式应用于特定元素中的所有TextBlock,只需将Style放在该元素资源中:
- <TextBlock /> <!-- unaffected -->
- <Grid>
- <Grid.Resources>
- <Style TargetType="TextBlock">
- <!-- ... -->
- </Style>
- </Grid.Resources>
- <TextBlock /> <!-- will be styled -->
- </Grid>
如果您将样式存储在单独的ResourceDictionary中,则可以通过合并资源字典来为特定元素“导入”它们:
- <Grid>
- <Grid.Resources>
- <ResourceDictionary>
- <ResourceDictionary.MergedDictionaries>
- <ResourceDictionary Source="/Resources/MyOtherStyles.xaml" />
- </ResourceDictionary.MergedDictionaries>
- </ResourceDictionary>
- </Grid.Resources>
- <TextBlock /> <!-- will be styled -->
- </Grid>