MultiBinding转换器,CheckBox.IsChecked不叫 [英] MultiBinding Converter in CheckBox.IsChecked not called
问题描述
我有一个自定义组合框一个multiselectioncombobox如果你愿意,
I have a custom combobox a multiselectioncombobox if you will,
的事情是选择依赖于一个其他集合。我试图ComboBox.IsChecked属性绑定到MultiBinding转换,但转换器不叫。
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>
和转换器是
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;
}
}
有什么建议?
推荐答案
尝试各种可能性之后,我发现周围的工作。我依然不明白为什么这可能工作,另一个则不会。
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.
我已经改变了我的XAML来传递整个对象,而不是财产。因此,code看了很喜欢这个,
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>
和所述转换器是
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.
这篇关于MultiBinding转换器,CheckBox.IsChecked不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!