Hi,
I would like to generally define my styles in the XAML, but add dynamic datatriggers on top in code-behind.
What I have in the xaml is like
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Background" Value="CadetBlue" />
</Style>
</igDP:XamDataGrid.Resources>
Somewhere in the code behind, I'd want to add, for example:
var dt = new DataTrigger
{
Binding = new Binding(bindingPath),
Value = true
};
dt.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(1)));
dt.Setters.Add(new Setter(Control.BorderBrushProperty, Brushes.Green));
Hello,
Thank you for your post. I have been looking through it and I created a sample project for you with the functionality you want. Basically I created a new Style, based on the one defined in XAML, and added a new Setter to it and then applied it to the XamDataGrid’s FieldSettings’ CellValuePresenterStyle Property. You can also add DataTriggers the same way. Please let me know if you need further clarification on this matter.
Looking forward for your reply.
Hi Stefan,
Thank you, this worked.
One further issue is I would like to bind the setter to an object that is a member property of my Record.DataItem
Currently I instantiate the member in a Grid_RecordAdded handler, eg:
((MyItem)e.Record.DataItem).MetaData = new ItemMetaData(e.Record.DataItem);
Unfortunately, it seems to only pick up the trigger binding item when I move on to another record. Is there a way to force rebinding in the Grid_RecordAdded handler?