0

もしよろしければ、私はカスタムコンボボックスを持っています。

問題は、選択が他のコレクションに依存することです。ComboBox.IsChecked プロパティを MultiBinding Converter にバインドしようとしましたが、コンバーターが呼び出されません。

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

助言がありますか?

4

1 に答える 1

0

可能性を試した後、回避策を見つけました。それでも、なぜこれが機能し、他の機能が機能しないのかはよくわかりません。

プロパティではなくオブジェクト全体を渡すように xaml を変更しました。コードはこのように見えたので、

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

これは間違いなく望ましい解決策ではありませんが、他の理由がわかるまでこれを行います。

于 2013-04-25T05:31:14.943 に答える