Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1410
Setting the style for UnboundField based on it's value?
posted

Hi.

Using XamDataGrid 2011.1

I've googled all the sites and checked Feature Browser for solution, but didn't find.

Given:

XamDataGrid with some unbound fields. Some of the fields are set for "indexer's" properties. Thus, unboundField's BindingPath property is set as:

["value1"]

["value2"]

["value3"]

.. and so on (with [ ] brackets!)

Correspoding Model object has indexer property like:

public string this[string attributeName] {
            get {
                ...
            }

And all works great, I can see those indexer values inside cells.

Now, I want to have custom CellValuePresenter style, such as: if value is equal to "x", - let the text be blue, if value is equal to "y" - let the text be green,  if value is equal to "True" - let it be checkbox displayed. What is displayed doesn't matter. What does matter is that I cannot dig into the "current" indexer property that is displayed. The Record.DataItem of the CellValuePresenter is always the main object, thus I don;'t know which value I'm displaying now.

 <Style x:Key="TimeSeriesCell" TargetType="{x:Type igDP:CellValuePresenter}">
                <Setter Property="ForegroundStyle">
                    <Setter.Value>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:DataRecordCellArea}}, Path=???????" Value="True">
                                    <Setter Property="TextBlock.Foreground" Value="Blue"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Setter.Value>
                </Setter>
            </Style>

What is under Path always referes to main object that contain the indexer property.

How to deal with it?

Parents
No Data
Reply
  • 3255
    posted

    Hello Lukas,

    You may set the Relative Source mode to self  and Path to Value in this case.  I would also suggest you to use a different style for each field i.e., create mulitple cellValuePresenter styles, one for each field so that you would know what field the style was being used for.

Children