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
55
How to create a DataRecordPresenterStyle DataTrigger from code
posted

I am trying to do this:

<Style TargetType="{x:Type igDP:DataRecordPresenter}">
  <Style.Triggers>
    <DataTrigger Binding="{Binding DataItem.IsOnChart}" Value="true">
      <Setter Property="Opacity" Value="1"/>
    </DataTrigger>
    <DataTrigger Binding="{Binding DataItem.IsOnChart}" Value="false">
      <Setter Property="Opacity" Value="0.5"/>
    </DataTrigger>
  </Style.Triggers>
</Style>


From C#:

Style _DataRecordPresenterStyle = new Style(typeof(DataRecordPresenter));
_DataRecordPresenterStyle.Setters.Add(new Setter(DataRecordPresenter.OpacityProperty, 1));
var _DataTrigger = new DataTrigger() { Binding = new Binding("DataItem.IsOnChart"), Value = true };
_DataTrigger.Setters.Add(new Setter(DataRecordPresenter.OpacityProperty, 1));
_DataRecordPresenterStyle.Triggers.Add(_DataTrigger);
_DataTrigger = new DataTrigger() { Binding = new Binding("DataItem.IsOnChart"), Value = false };
_DataTrigger.Setters.Add(new Setter(DataRecordPresenter.OpacityProperty, 0.5));
_DataRecordPresenterStyle.Triggers.Add(_DataTrigger);
_Grid.FieldLayoutSettings.DataRecordPresenterStyle = _DataRecordPresenterStyle;

But when I bind the data to the grid I get the error:

Default Unhandled exception: Exception has been thrown by the target of an invocation.

What am I doing wrong here?

Thanks for your time.