title: XamDataGrid - How to create a DataRecordPresenterStyle DataTrigger from C# code
body: <p>I am trying to do this:</p>
  
  <pre><code>&lt;Style TargetType="{x:Type igDP:DataRecordPresenter}"&gt;
      &lt;Style.Triggers&gt;
          &lt;DataTrigger Binding="{Binding DataItem.IsOnChart}" Value="true"&gt;
              &lt;Setter Property="Opacity" Value="1"/&gt;
          &lt;/DataTrigger&gt;
          &lt;DataTrigger Binding="{Binding DataItem.IsOnChart}" Value="false"&gt;
              &lt;Setter Property="Opacity" Value="0.5"/&gt;
          &lt;/DataTrigger&gt;
      &lt;/Style.Triggers&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>From C#:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>But when I bind the data to the grid I get the error:</p>
  
  <p>Default Unhandled exception: Exception has been thrown by the target of an invocation.</p>
  
  <p>The data does have the field, it's type is a bool and the value is true on all records.</p>
  
  <p>What am I doing wrong here?</p>
  
  <p>Thanks for your time.</p>