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));
This works fine if the field is a a boolean, but what if the field driven the style is a text editor or combo box? is there a generic way of handling it?
Hello again,
I have been looking through your sample and I edited, so now it works as you want. Basically I added a handler for the XamCheckEditor and make it EndEditMode and StartEditMode whenever its value changes. This way the triggers are applied.
Hope this helps you
Hi Stefan,
Please see the attached project. As you can see, the data trigger does not kick in for a new record until you've moved off (eg: by pressing return).
I am glad that I helped you resolve your issue. As for your new question I am not that I completely understand it, but still I made some changes to the sample I send you before and reattached it. If this is not what you need, could you please be more specific on what you are trying to achieve.
Looking forward for your reply.
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?