我正在WPF应用程序中实现附加行为.我需要传递一个类型参数的行为,这样我就可以调用一个方法void NewRow(Table<T> table)上SqliteBoundRow.如果我在XAML中实例化一个对象,我会使用类型参数传递x:TypeArguments,但是在设置附加行为时我没有看到这样做的方法,因为它使用静态属性.
附加行为的代码如下所示:
public abstract class SqliteBoundRow<T> where T : SqliteBoundRow<T>
{
public abstract void NewRow(Table<T> table);
}
public class DataGridBehavior<T> where T:SqliteBoundRow<T>
{
public static readonly DependencyProperty IsEnabledProperty;
static DataGridBehavior()
{
IsEnabledProperty = DependencyProperty.RegisterAttached("IsEnabled",
typeof(bool), typeof(DataGridBehavior<T>),
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 …Run Code Online (Sandbox Code Playgroud)