Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this multibinding not working

I have sending multiple parameters from my Checkbox Command. I have used a converter. The code is below. If i put a debugger and see the values here are my results :

When checkbox check is either checked or unchekcked :

In the converter it has teh values (Array of the item object and boolean). But when i come to my method, the value is a object[2] but both values are NULL

CheckBox XAML

 <CheckBox x:Name="checkBox" 
              Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.Data.Label}"   
              ClickMode="Release"
              Command="{Binding Path=DataContext.SelectUnSelect}">
        <CheckBox.CommandParameter>
            <MultiBinding Converter="{StaticResource SelectedItemConverter}">
                <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Content.Data"/>
                <Binding RelativeSource="{RelativeSource Self}" Path="IsChecked"/>
            </MultiBinding>
        </CheckBox.CommandParameter>

Convertor :

 public class CheckConverter : 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();
    }
} 

View Model Command Code :

public ICommand SelectUnSelect
    {
        get { return new RelayCommand<object>(parm => this.SelectAndUnSelect(parm));}
    }

If i put a debugger in SelectAndUnSelect method, it shows me object[2] in parm but both of them are null.

Observation : If i bind my command parameter to any one of the bindings it works fine.

What am i missing here ?

  • Shankar
like image 533
Shankar Avatar asked Oct 01 '11 00:10

Shankar


1 Answers

I've had the same problem before, if I remember correctly then returning values.ToList() instead of just values should fix it

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
    return values.ToList();
}
like image 119
Fredrik Hedblad Avatar answered Oct 20 '22 09:10

Fredrik Hedblad