Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 918
Amanduh Avatar asked Dec 08 '25 09:12

Amanduh


1 Answers

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...

like image 174
Amanduh Avatar answered Dec 10 '25 02:12

Amanduh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!