Why is this multibinding not working

我怕爱的太早我们不能终老 提交于 2019-12-30 18:28:18

问题


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

回答1:


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();
}


来源:https://stackoverflow.com/questions/7617375/why-is-this-multibinding-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!