IMultiValueConverter values ​​are ok, but CommandParameter is NULL

I am trying to pass multiple values ​​through IMultiValueConverter to a command (as a command parameter). The values ​​are correct when they pass through the converter, but as soon as the Can_Execute () and Execute () commands are 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>

Class IMultiValueConverter:

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 fine when I did not use MultiBinding and the converter, but I need MultiBinding, so I can pass additional information to the command.

+3
source share
1 answer

The return values ​​.Clone () instead of just the values ​​from the converter seems to fix the problem, but I'm not sure if this is the best thing to do ...

+6
source

Source: https://habr.com/ru/post/1783678/


All Articles