private static void OnSetCommandParameterCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { ListBox lb = dependencyObject as ListBox; if (lb != null) { ListBoxSelectionChangedCommandBehavior behavior = GetOrCreateBehavior(lb); behavior.CommandParameter = e.NewValue; } }
private static ListBoxSelectionChangedCommandBehavior GetOrCreateBehavior(ListBox listBox) { ListBoxSelectionChangedCommandBehavior behavior = listBox.GetValue(SelectCommandBehaviorProperty) as ListBoxSelectionChangedCommandBehavior; if (behavior == null) { behavior = new ListBoxSelectionChangedCommandBehavior(listBox); listBox.SetValue(SelectCommandBehaviorProperty, behavior); } return(behavior); }