Search code examples
wpfmultibindingcommandparameter

IMultiValueConverter values are okay, but CommandParameter is null


I am trying to pass several values through an IMultiValueConverter to a command (as the command parameter). The values are correct when they go through the converter, but once the Can_Execute() and Execute() comands get called, I get an array of null objects. Any ideas?

Xaml:

    <Button Content="+" HorizontalAlignment="Right" VerticalAlignment="Top" Width="23" Height="23" Margin="0,0,0,0">
        <Button.CommandParameter>
            <MultiBinding Converter="{StaticResource Converter_MultipleValues}">
                <Binding/>
            </MultiBinding>
        </Button.CommandParameter>
        <Button.Command>
            <Binding Path="Command_Add_Files" Source="{StaticResource Vm_FileList}"/>
        </Button.Command>
    </Button>

IMultiValueConverter class:

class cvt_multivalue : IMultiValueConverter {
    public object Convert (object[] Values, Type Target_Type, object Parameter, CultureInfo culture) {
        if (Target_Type != typeof (object)) throw new NotSupportedException ();
        return Values;
        }

    public object [] ConvertBack (object Value, Type [] Target_Type, object Parameter, CultureInfo culture) {
        throw new NotSupportedException ();
        }
    }

The code worked just fine when I wasn't using a MultiBinding and converter, but I need the MultiBinding so I can pass some extra information to the command.


Solution

  • Returning Values.Clone() instead of just Values from the converter seems to fix the problem, but I'm not sure if that is the best thing to be doing...