I tried to used the style as mentioned in this post http://ko.infragistics.com/community/forums/p/51185/268258.aspx
However instead of using the EditorStyle (Editor) I defined the CellValuePresenterStyle. The reason for this was I already have CellValuePresenterStyle for Border related properties. Do I need to define both the EditorStyle and CellValuePresenterStyle.
In the following example 'name' is using EditorStyle and works. While 'department' is using CellValuePresenterStyle' and does NOT work.
<igDP:XamDataGrid BindToSampleData="True"> <igDP:XamDataGrid.Resources> <Style x:Key="StrikeThroughEditor" TargetType="{x:Type editors:XamTextEditor}" BasedOn="{StaticResource {x:Type editors:XamTextEditor}}"> <Style.Resources> <Style TargetType="{x:Type controls:SimpleTextBlock}"> <Setter Property="TextDecorations" Value="Strikethrough" /> </Style> </Style.Resources> </Style> <Style x:Key="StrikeThroughCellValuePresenter" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}"> <Style.Resources> <Style TargetType="{x:Type controls:SimpleTextBlock}"> <Setter Property="TextDecorations" Value="Strikethrough"/> </Style> </Style.Resources> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:Field Name="name"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource StrikeThroughEditor}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="department"> <igDP:Field.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource StrikeThroughCellValuePresenter}" /> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
<igDP:XamDataGrid BindToSampleData="True"> <igDP:XamDataGrid.Resources> <Style x:Key="StrikeThroughEditor" TargetType="{x:Type editors:XamTextEditor}" BasedOn="{StaticResource {x:Type editors:XamTextEditor}}"> <Style.Resources> <Style TargetType="{x:Type controls:SimpleTextBlock}"> <Setter Property="TextDecorations" Value="Strikethrough" /> </Style> </Style.Resources> </Style>
<Style x:Key="StrikeThroughCellValuePresenter" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}"> <Style.Resources> <Style TargetType="{x:Type controls:SimpleTextBlock}"> <Setter Property="TextDecorations" Value="Strikethrough"/> </Style> </Style.Resources> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:Field Name="name"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource StrikeThroughEditor}" /> </igDP:Field.Settings> </igDP:Field>
<igDP:Field Name="department"> <igDP:Field.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource StrikeThroughCellValuePresenter}" /> </igDP:Field.Settings> </igDP:Field>
</igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Hi Rob,
Thanks for the information. It has cleared all my queries.
Hi Bhavesh,
Let me know if you have any further questions on this matter.
A colleague pointed out to me that the real reason the style isn't applied to the SimpleTextBlock through the CellValuePresenter is because implicit styles are not applied to controls that do not derive from the Control class. This article he sent me explains this. This doesn't really change the fact that you'll still need to apply your editor style along with your CellValuePresenter style.
As to your question, I don't believe there is any limitation on setting both of them. The only time I could see this being an issue is if you created a style for the CellValuePresenter that overwrote the template for it. In this case your editor style might not get applied depending on what you did in the template.
I updated the FieldSettings and setup both CellValuePresenterStyle and EditorStyle. And this fixes the problem.
I have a follow-up question, I remember reading somewhere is documentation about setting either EditorStyle or CellValuePresenterStyle. Here I am setting both. Is this going to give me grief ?
<igDP:XamDataGrid BindToSampleData="True"> <igDP:XamDataGrid.Resources> <Style TargetType="{x:Type controls:SimpleTextBlock}" BasedOn="{StaticResource {x:Type controls:SimpleTextBlock}}"> <Setter Property="TextDecorations" Value="Strikethrough" /> </Style> <Style x:Key="StrikeThroughEditor" TargetType="{x:Type editors:XamTextEditor}" BasedOn="{StaticResource {x:Type editors:XamTextEditor}}"> <Style.Resources> <Style TargetType="{x:Type controls:SimpleTextBlock}"> <Setter Property="TextDecorations" Value="Strikethrough" /> </Style> <Style TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}"></Style> </Style.Resources> </Style> <Style x:Key="StrikeThroughCellValuePresenter" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}"> <Setter Property="BorderBrush" Value="Brown"></Setter> <Setter Property="BorderThickness" Value="2"></Setter> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:Field Name="name"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource StrikeThroughEditor}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="department"> <igDP:Field.Settings> <!--NOTE: Setting both the CellValuePresenterStyle and EditorStyle --> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource StrikeThroughCellValuePresenter}" EditorStyle="{StaticResource StrikeThroughEditor}"/> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
<igDP:XamDataGrid BindToSampleData="True"> <igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type controls:SimpleTextBlock}" BasedOn="{StaticResource {x:Type controls:SimpleTextBlock}}"> <Setter Property="TextDecorations" Value="Strikethrough" /> </Style> <Style x:Key="StrikeThroughEditor" TargetType="{x:Type editors:XamTextEditor}" BasedOn="{StaticResource {x:Type editors:XamTextEditor}}"> <Style.Resources> <Style TargetType="{x:Type controls:SimpleTextBlock}"> <Setter Property="TextDecorations" Value="Strikethrough" /> </Style> <Style TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}"></Style> </Style.Resources> </Style>
<Style x:Key="StrikeThroughCellValuePresenter" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}"> <Setter Property="BorderBrush" Value="Brown"></Setter> <Setter Property="BorderThickness" Value="2"></Setter> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:Field Name="name"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource StrikeThroughEditor}" /> </igDP:Field.Settings> </igDP:Field>
<igDP:Field Name="department"> <igDP:Field.Settings> <!--NOTE: Setting both the CellValuePresenterStyle and EditorStyle --> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource StrikeThroughCellValuePresenter}" EditorStyle="{StaticResource StrikeThroughEditor}"/> </igDP:Field.Settings> </igDP:Field>
The only thing I can think of is that the style located in the CellValuePresenter's Style.Resources for the SimpleTextBlock can't cross the ContentPresenter barrier. The CellValuePresenter template has a ContentPresenter called PART_EditorSite. Depending on the data type of the column the content placed in the ContentPresenter will differ. This is acting like a barrier and content inside the presenter doesn't know anything about the CellValuePresenter which means it ignores the style for SimpleTextBlock.
This explains why it doesn't work when using the CellValuePresenter. You need to use the EditorStyle property in order to apply the Strikethrough to the text as this style is directly applied to the ValueEditor located in the CellValuePresenter's PART_EditorSite.