2012-12-04 17 views
7

मैं बस कमांड पैरामीटर के रूप में दो नियंत्रणों को बांधने की कोशिश कर रहा हूं और उन्हें object[] के रूप में अपने आदेश में पास कर रहा हूं।डब्ल्यूपीएफ कमांड पैरामीटर मल्टीबाइंडिंग मान शून्य

XAML:

<UserControl.Resources> 
     <C:MultiValueConverter x:Key="MultiParamConverter"></C:MultiValueConverter> 
    </UserControl.Resources> 

    <StackPanel Orientation="Vertical"> 
     <StackPanel Orientation="Horizontal"> 
      <Button Name="Expander" Content="+" Width="25" Margin="4,0,4,0" Command="{Binding ExpanderCommand}"> 
       <Button.CommandParameter> 
        <MultiBinding Converter="{StaticResource MultiParamConverter}"> 
         <Binding ElementName="Content"/> 
         <Binding ElementName="Expander"/> 
        </MultiBinding> 
       </Button.CommandParameter> 
      </Button> 
      <Label FontWeight="Bold">GENERAL INFORMATION</Label> 
     </StackPanel> 
     <StackPanel Name="Content" Orientation="Vertical" Visibility="Collapsed"> 
      <Label>Test</Label> 
     </StackPanel> 
    </StackPanel> 

कमान:

public ICommand ExpanderCommand 
     { 
      get 
      { 
       return new RelayCommand(delegate(object param) 
        { 
         var args = (object[])param; 
         var content = (UIElement)args[0]; 
         var button = (Button)args[1]; 
         content.Visibility = (content.Visibility == Visibility.Visible) ? Visibility.Collapsed : Visibility.Visible; 
         button.Content = (content.Visibility == Visibility.Visible) ? "-" : "+"; 
        }); 
      } 
     } 

कनवर्टर:

public class MultiValueConverter : IMultiValueConverter 
    { 
     public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
     { 
      return values; 
     } 

     public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) 
     { 
      throw new NotImplementedException("No two way conversion, one way binding only."); 
     } 
    } 

असल में क्या हो रहा है कि बाध्यकारी काम करने ठीक लग रहा है और कनवर्टर एक लौटा रहा है object[] सही मान रखते हैं, हालांकि जब आदेश पैरा को निष्पादित करता है मी object[] है जिसमें तत्वों की संख्या समान है, सिवाय इसके कि वे null हैं।

क्या कोई मुझे बता सकता है कि object[] पैरामीटर के मान null पर क्यों सेट किए जा रहे हैं?

धन्यवाद, एलेक्स।

उत्तर

15

यह बात करेंगे:

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 
{ 
    return values.ToArray(); 
} 

विवरण के लिए इस question पर एक नजर डालें।