title: Pass type parameters to attached behaviors
body: <p>I am implementing an attached behavior in a WPF application.  I need to pass a type parameters  to the behavior, so I can call a method <code>void NewRow(Table&lt;T&gt; table)</code> on <code>SqliteBoundRow</code>.  If I was instantiating an object in XAML, I would pass a type parameters using <code>x:TypeArguments</code>, but I don't see a way to do this when setting an attached behavior, because it uses a static property.</p>
  
  <p>Code for the attached behavior looks like this:</p>
  
  <pre><code>public abstract class SqliteBoundRow&lt;T&gt; where T : SqliteBoundRow&lt;T&gt;
  {
      public abstract void NewRow(Table&lt;T&gt; table);
  }
  
  public class DataGridBehavior&lt;T&gt; where T:SqliteBoundRow&lt;T&gt;
  {
      public static readonly DependencyProperty IsEnabledProperty;
      static DataGridBehavior()
      {
          IsEnabledProperty = DependencyProperty.RegisterAttached("IsEnabled",
              typeof(bool), typeof(DataGridBehavior&lt;T&gt;),
              new FrameworkPropertyMetadata(false, OnBehaviorEnabled));
      }
      public static void SetIsEnabled(DependencyObject obj, bool value)
      {
          obj.SetValue(IsEnabledProperty, value);
      }
      public static bool GetIsEnabled(DependencyObject obj)
      {
          return (bool)obj.GetValue(IsEnabledProperty);
      }
      private static void OnBehaviorEnabled(DependencyObject dependencyObject,
          DependencyPropertyChangedEventArgs args)
      {
          var dg = dependencyObject as DataGrid;
          dg.InitializingNewItem += DataGrid_InitializingNewItem;
      }
      private static void DataGrid_InitializingNewItem(object sender,
          InitializingNewItemEventArgs e)
      {
          var table = (sender as DataGrid).ItemsSource as Table&lt;T&gt;;
          (e.NewItem as T).NewRow(table);
      }
  
  }
  </code></pre>
  
  <p>XAML looks like this:</p>
  
  <pre><code>&lt;DataGrid DataGridBehavior.IsEnabled="True"&gt;
      &lt;!-- DataGridBehavior needs a type parameter --&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>My current solution is to wrap DataGridBehavior in a a derived class which specifies the type parameters.</p>