且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

多重绑定中的DependencyProperty.unsetValue

更新时间:2023-10-03 21:25:58

Multi的第一个绑定应该是到Books ListBox中的SelectedItem。我在适当的地方添加了< CheckBox.IsChecked> ,并将Content = {Binding}添加到CheckBox中:

The first Binding of the Multi should be to be to the SelectedItem in the ListBox of Books. I have added in the <CheckBox.IsChecked> where appropriate, and Content="{Binding}" to the CheckBox:

                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <CheckBox Width="200" Content={Binding}>
                              <CheckBox.IsChecked>
                                <MultiBinding Converter="{StaticResource TextInListTrueFalseConverter}" >
                                    <Binding ElementName=listBoxBooks, Path=SelectedItem.KeywordsForTextbox"></Binding>
                                    <Binding RelativeSource="{RelativeSource Self}" Path="Content"></Binding>
                                </MultiBinding>
                              </CheckBox.IsChecked>
                            </CheckBox>
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>

您可能还希望向IMultiValueConverter添加一些验证以确保传递的值未设置,以避免发生异常:如果VB中的not values(0)是DependencyProperty.UnsetValue而不是values(1)是DependencyProperty.UnsetValue然后

You may also wish to add some validation to the IMultiValueConverter to make sure the passed values are not unset, to avoid an exception: If Not values(0) Is DependencyProperty.UnsetValue And Not values(1) Is DependencyProperty.UnsetValue Then in VB.

关于选中复选框的行为,我猜这是因为ConvertBack IMul​​tiValueConverter的方法。您可以删除抛出异常代码,并编写一种方法来将选中/未选中框的文本添加/删除到关键字列表中。

Regarding the behaviour on checking the checkbox, I am guessing this is because of the ConvertBack Method of the IMultiValueConverter. You can remove the 'Throw Exception' code, and write a method to add/remove the text of the checked/unchecked box to your keyword list.