MultiBinding Converter in CheckBox.IsChecked not called
Asked Answered
P

1

0

I have a custom combobox a multiselectioncombobox if you will,

the thing is the selections depend on an other collection. I tried to bind ComboBox.IsChecked property to MultiBinding Converter but the converter isn't called.

<DataTemplate>
<StackPanel Orientation="Horizontal" x:Name="ItemStack" VirtualizingStackPanel.IsVirtualizing="False">
    <CheckBox x:Name="CheckBoxItem"
        Command="{Binding SelectItem, RelativeSource={RelativeSource AncestorType={x:Type MultiSelectionComboBox}}}"
        CommandParameter="{Binding Key}"
              >
        <CheckBox.IsChecked>
            <MultiBinding Converter="{StaticResource MultiSelectionCommandConverter}" Mode="OneWay">
                <Binding Path="Key"/>
                <Binding Path="SelectedItem"
                         RelativeSource="{RelativeSource AncestorType={x:Type MultiSelectionComboBox}}" />
            </MultiBinding>
        </CheckBox.IsChecked>
    </CheckBox>
    <TextBlock Text="{Binding DisplayText}"></TextBlock>
</StackPanel>
</DataTemplate>

and the converter is,

public class MultiSelectionCommandConverter : IMultiValueConverter 
{      
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {   
            ///stuff to do...
    }

    public object[] ConvertBack(object values, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        return null;
    }
}

any suggestions?

Pros answered 24/4, 2013 at 8:5 Comment(2)
can you show the complete xaml of the combobox?Margaretamargarete
Are you getting any binding errors in your output?Euxenite
P
0

After trying out possibilities, I've found a work around. Still I'm not quite sure why this might work and the other won't.

I've changed my xaml to pass the whole object instead of the property. So the code looked liked this,

<DataTemplate>
<StackPanel Orientation="Horizontal" x:Name="ItemStack" VirtualizingStackPanel.IsVirtualizing="False">
    <CheckBox x:Name="CheckBoxItem"
        Command="{Binding SelectItem, RelativeSource={RelativeSource AncestorType={x:Type MultiSelectionComboBox}}}"
        CommandParameter="{Binding Key}"
              >
        <CheckBox.IsChecked>
            <MultiBinding Converter="{StaticResource MultiSelectionCommandConverter}" Mode="OneWay">
                <Binding Path="Key"/>
                <Binding 
                         RelativeSource="{RelativeSource AncestorType={x:Type MultiSelectionComboBox}}" />
            </MultiBinding>
        </CheckBox.IsChecked>
    </CheckBox>
    <TextBlock Text="{Binding DisplayText}"></TextBlock>
</StackPanel>
</DataTemplate>

and the converter is

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
    string key = (string)values[0];
    ObservableCollection<ListItem> selectedItems = (values[1] as MultiSelectionComboBox).SelectedItem;
    //do stuff
    return false;
}

This is definitely not a desired solution but, this will do until i figure out the other reason.

Pros answered 25/4, 2013 at 5:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.