WPF CommandParameter MultiBinding null values

I'm just trying to bind two controls as command parameters and pass them to my command as 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> 

Team:

 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) ? "-" : "+"; }); } } 

Converter

 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."); } } 

Basically, what happens is that the binding seems to work fine, and the converter returns an object[] containing the correct values, however, when the command executes the parameter, it is an object[] containing the same number of elements, except that they are null .

Can someone tell me why the values โ€‹โ€‹of the object[] parameter are set to null ?

Thanks, Alex.

+7
source share
1 answer

This will do the following:

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

Take a look at this question for an explanation.

+15
source

All Articles