//attached 属性建立目标控件和behavior对象之间的关系 private static void OnSetCommandCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { RadGridView gridView = dependencyObject as RadGridView; if (gridView != null) { RadGridViewRowActivatedBehavior behavior = GetOrCreateBehavior(gridView); behavior.Command = e.NewValue as ICommand; } }
private static RadGridViewRowActivatedBehavior GetOrCreateBehavior(RadGridView gridView) { RadGridViewRowActivatedBehavior behavior = gridView.GetValue(RowActivatedCommandBehaviorProperty) as RadGridViewRowActivatedBehavior; if (behavior == null) { behavior = new RadGridViewRowActivatedBehavior(gridView); gridView.SetValue(RowActivatedCommandBehaviorProperty, behavior); } return(behavior); }