Welcome to the Xceed Community | Help
Community Search  
More Search Options

Combining Style, DataTemplate and Converter on DataCell and DataRow

Sort Posts: Previous Next
  •  03-27-2009, 10:58 AM Post no. 19700

    Combining Style, DataTemplate and Converter on DataCell and DataRow

    Hi,

    I'm trying to customize my DataGrid display depending on the data it contains.

    What I need to have is:

       1) Changing the colour of some DataRows depending on a property of the displayed object (in order to highlight the active DataRows)

       2) Displaying some entire DataRows with strikethrough text depending on a property of the displayed object (in order to highlight invalid data)

       3) Having a custom display for some columns depending on the data stored in the cell (in order to display information easier to understand)

     

    What I am using right now is:

       1) A Style applied on DataRow objects to change the colour of the line

       2) A Style applied on DataCell objects that modify the ControlTemplate in order to use a TextBlock with the TextDecorations set to Strikethrough

       3) A DataTemplate applied on a Column that uses a ContentPresenter using a Converter that modifies the data displayed (in order to replace the value "-1" by the text "Infinity" for example)

     

    My problem is that when I try to use my second Style that modify the ControlTemplate, the DataTemplate/Converter is not applied. 

    My questions are:

       1) How can I apply my Styles and my DataTemplate at the same time ? 

        2) Is there another way to achieve what I want ?

     

    Thanks a lot. 

  •  03-27-2009, 2:54 PM Post no. 19707 in reply to 19700

    Re: Combining Style, DataTemplate and Converter on DataCell and DataRow

    check out my post on this thread where I used DataTemplateSelector to choose the template based on the value in a column

    http://xceed.com/CS/forums/thread/19652.aspx

    I also have different CellEditor for different types of data in this thread

    http://xceed.com/CS/forums/thread/19593.aspx

    Also I believe there is something like ItemContainerStyleSelector which does the styles but I am not sure on that

    Hope it helps

    Shams

  •  03-30-2009, 8:17 AM Post no. 19723 in reply to 19707

    Re: Combining Style, DataTemplate and Converter on DataCell and DataRow

    I think your code will be helpful on the next step for me, that is to say selecting the correct DataTemplate depending on a property of my data.

    What bothers me now is mixing the DataTemplate I had set to my column's CellContentTemplate and the ControlTemplate used in my DataCell's Style.

    I think I can solve my problem using a TemplateBinding, but I can't figure out how...

    Here is what I have done for now:

       1) My DataTemplate:

            <conv:RelativeAbsoluteTimeConverter_C x:Key="relativeTimeConverter" />

            <DataTemplate x:Key="relativeTimeCellDataTemplate"

                          x:Name="relativeTimeCellDataTemplate">

                <ContentPresenter Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type xcdg:Cell}}, 

                    Path=DataContext, 

                    Mode=TwoWay, 

                    Converter={StaticResource relativeTimeConverter},

                    ConverterParameter={StaticResource dataSourceBus}}" />

            </DataTemplate> 

     

       2) My Column definition:

                    <xcdg:DataGridControl.Columns>

                        <xcdg:Column FieldName="Time"

                                     Title="Time (µs)"

                                     ReadOnly="True"

                                     CellContentTemplate="{StaticResource relativeTimeCellDataTemplate}"/> 

     

       3) The Style used on my cells:

        <Style TargetType="xcdg:DataCell"

               BasedOn="{StaticResource DefaultDataCellStyle}"

               x:Key="DataCellTextBlockStyle">

            <Setter Property="Template">

                <Setter.Value>

                    <ControlTemplate TargetType="xcdg:DataCell">

                        <TextBlock VerticalAlignment="Center"> 

                            <!-- Here is my problem ! I don't know how to get the Column's CellContentTemplate... --> 

                            <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" />

                            <!--<ContentPresenter ContentTemplate="{TemplateBinding xcdg:Column.CellContentTemplate}"/>-->

                            <!--<ContentPresenter ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" />-->

                            <!--<ContentPresenter ContentTemplate="{TemplateBinding xcdg:DataCell.ParentColumn.CellContentTemplate}" />-->

                        </TextBlock>

                        <ControlTemplate.Resources>

                            <Style TargetType="{x:Type TextBlock}">

                                <Style.Triggers>

                                    <DataTrigger Binding="{Binding Path=IsValid}"

                                                 Value="False">

                                        <Setter Property="Foreground"

                                                Value="Red" />

                                        <Setter Property="TextDecorations">

                                            <Setter.Value>

                                                <TextDecorationCollection>

                                                    <TextDecoration Location="Strikethrough"

                                                                    PenOffset="0.75" />

                                                </TextDecorationCollection>

                                            </Setter.Value>

                                        </Setter>

                                    </DataTrigger>

                                </Style.Triggers>

                            </Style>

                        </ControlTemplate.Resources>

                    </ControlTemplate>

                </Setter.Value>

            </Setter>

        </Style> 

     

    If anyone has an idea on how to link my ContentPresenter ContentTemplate on my DataTemplate, that would be great. 

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.