示例#1
0
        private static void OnSetCommandParameterCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ComboBox cb = d as ComboBox;

            if (cb != null)
            {
                //Acquire behavior attached to the list view and set the command parameter
                //The behavior class executes the command
                ComboBoxSelectCommandBehavior behavior =
                    GetOrCreateBehavior(cb);
                behavior.CommandParameter = e.NewValue;
            }
        }
示例#2
0
        private static ComboBoxSelectCommandBehavior GetOrCreateBehavior(ComboBox cb)
        {
            //First get the behavior, maybe it is already created
            ComboBoxSelectCommandBehavior behavior =
                cb.GetValue(SelectCommandBehaviorProperty) as ComboBoxSelectCommandBehavior;

            if (behavior == null)
            {
                //if the behavior is not created then create one
                behavior = new ComboBoxSelectCommandBehavior(cb);
                cb.SetValue(SelectCommandBehaviorProperty, behavior);
            }
            //return the behavior
            //Caller function sets the command or command parameter properties
            return(behavior);
        }