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?
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.
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
Hi Asma
Thx for replies.
I'm still struggling with this problem.
What I don't know is how to set Binging for this CheckboxCell style soo that it points to the value of current cell, not entire row.
Having:
Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:DataRecordCellArea}}
Points to the entire model object that is bound to the row.
How to set this binding to the current cell ? (in order to either set Checkbox checked, or unchecked).
Note: Checkbox cell style declaration doesn't know about which value .. value1, value2, value3 .. etc, because it's set for all the values.
Hi Lukas,
You could use the DataRecord’s DataItem and point to any of the underlying data.
I created the following viewmodel and bound it to my DataContext.
this.DataContext = vm;
public class ViewModel
{
//public Dictionary<int, Test> MyDict { get; set; }
public Dictionary<String, Test> MyDict { get; set; }
public ViewModel()
MyDict = new Dictionary<string,Test>();
for (int i = 0; i < 10;i++ )
Test t = new Test();
t.Name = "name" + i.ToString();
t.Values = new List<string>();
for (int j=0;j<= i;j++)
t.Values.Add("List Item" + i.ToString() + "-" + j.ToString());
}
MyDict.Add("key"+i.ToString(),t);
Here is the xaml I used to apply a style based on the value of the Name in my datarecord.
<igDP:UnboundField BindingPath="Value.Name">
<igDP:UnboundField.Settings>
<igDP:FieldSettings>
<igDP:FieldSettings.CellValuePresenterStyle>
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="ForegroundStyle">
<Setter.Value>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=DataItem.Value.Name}" Value="name1">
<Setter Property="TextBlock.Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Setter.Value>
</Setter>
</igDP:FieldSettings.CellValuePresenterStyle>
</igDP:FieldSettings>
</igDP:UnboundField.Settings>
</igDP:UnboundField>
Or you could use one of the other bound cell values
<DataTrigger Binding="{Binding Path=Cells[Key].Value}" Value="key1">
You might want to also use the following link as a reference to binding
http://community.infragistics.com/forums/p/34812/202511.aspx
Please let me know if you have any questions.
Thx for this!
Actually, it was your link that finally helped to solve this issue.
What I was missing was:
RelativeSource={RelativeSource TemplatedParent}
And now, checkbox can dig into current "cell value" , not entire "row value".
This is propably because In my style I used <Setter Property="Template">.
Anyway, Thx once again!
Hi,
Thanks for letting me know. Glad I could be of some assistance.
Please let me know if I can be any further help.