我正在使用Infragistics 2014.2。我有一个XamDataGrid,它使用动态列显示数据,网格按其默认样式进行格式化,此外,一些列的对齐设置为右(十进制类型列),其中有一些值屏蔽,其余列设置为对齐离开。
我想删除XamDataGrid的默认CellValuePresenter样式,并在其上编写一个仅包含TextBlock / ContentPresenter的新样式,而不是每个单元格的CellValuePresenter,并且在应用新样式后,单元格的对齐和屏蔽应保持相同。应用这种新风格的原因是我希望同一网格的副本在另一个窗口上显示它,而不需要数据操作。
请你看一下我试图达到的相同代码(即使有很多变化),但无论如何它似乎都无法工作。
<Style x:Key="PreviewCellValuePresenterStyle" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate x:Name="CellValuePresenterControlTemplate" TargetType="{x:Type igDP:CellValuePresenter}">
<ContentPresenter x:Name="ContentValuePresenter"
VerticalAlignment="Center"
ContentSource="Value"
Margin="4,3,4,4"/>
<ControlTemplate.Triggers>
<Trigger Property="HorizontalAlignment" Value="Right">
<Setter TargetName="ContentValuePresenter" Property="TextBlock.TextAlignment" Value="Right"></Setter>
</Trigger>
<Trigger Property="HorizontalContentAlignment" Value="Right">
<Setter TargetName="ContentValuePresenter" Property="TextBlock.TextAlignment" Value="Right"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
现在,我只是设置了对齐属性进行测试。在上面的代码中,尝试使用TextBlock代替ContentPresenter,但是永远不会调用触发器。我不在哪里我做错了。
你能帮助我摆脱这个吗?
由于
答案 0 :(得分:0)
If your intention of using text block is only for alignment/appearance, then you can just use setters to set these values.
<Style x:Key="PreviewCellValuePresenterStyle" TargetType="{x:Type igDP:CellValuePresenter}" >
<Setter Property="FontWeight" Value="DemiBold"/>
<Setter Property="Height" Value="24"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
</Style>
But, If you need some other implementations like value masking, or need text block to be there,
<Style x:Key="PreviewCellValuePresenterStyle" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<TextBlock HorizontalAlignment="Center" Style="{DynamicResource TextStyle}">
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="TextStyle" TargetType="{x:Type TextBlock}">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>