【发布时间】:2013-04-22 19:42:42
【问题描述】:
我正在设计 CellValuePresenter(来自 Infragistics)以赋予 Gid Lines 不同的外观,并定义了一个样式 (gridLineStyle) 并应用于 Grid 的 CellValuePresenterStyle 属性。
我发现有些列的自定义模板是通过模板化 CellValuePrenter 定义的,并且网格线不可见(如预期的那样)。我可以通过应用 BasedOn 属性使其工作,如
<Style x:Key="gridLineStyle" TargetType="ig:CellValuePresenter">
<Setter Property="BorderThickness" Value="0,0,1,1"/>
<Setter Property="BorderBrush" Value="{Binding Path=BorderBrushForAllCells,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type pwc:CarbonBlotter}}}"/>
</Style>
<Style x:Key="anotherColumnStyle" TargetType="{x:Type ig:CellValuePresenter}" BasedOn="{StaticResource gridLineStyle}">
<Setter Property="Template">
....
<pwc:BaseXamDataGrid>
<pwc:BaseXamDataGrid.FieldSettings>
<ig:FieldSettings CellValuePresenterStyle="{StaticResource gridLineStyle}"
...
但是自定义模板有很多样式,我只是想知道我是否可以在不使用 BasedOn 属性但继承默认样式的情况下定义样式
【问题讨论】:
-
如果不重新创建整个样式定义,您可能无法跳过 BasedOn,这可能需要做很多工作。您可以做的是您可以跳过 x:Key 属性,并且此样式将成为其范围内所有
ig:CellValuePresenters 的默认样式 -
@StenPetrov 如果我从 gridLinesStyles 中删除 x:key,它将成为所有 CellValuePresenters 的默认值,除了模板化的那些(如在 anotherColumnStyle 中),它不会继承默认样式,不是吗。这正是我想要解决的问题。
-
正确。如果您在某处使用了 Style 属性,则默认样式不会是这个。
-
Infragistics 不提供带有样式的 xaml 资源文件吗?如果是这样,您可以修改 xaml 文件以满足您的需求...
-
@DeanKuga 当您像在 anotherColumnStyle 中一样重新设置它的样式时,它将不再尊重原始样式,不是吗?
标签: wpf