1

UserControlを閉じると、コンボボックスのSelectedIndex値が失われるという問題があります。ViewModelにはまだそれがありますが、ビューはそれを-1にリセットし続けます。ItemSourceとSelectedIndexのバインド順序に問題があることは理解していますが、ItemSourceに直接バインドしていません。基本的に、私は以下のバインディングの適切な構文を理解しようとしています。

               </ComboBox.ItemTemplate>
                <ComboBox.ItemsSource>
                    <CompositeCollection>
                        <ComboBoxItem IsEnabled="False">Select a database connection...</ComboBoxItem>
                        <CollectionContainer Collection="{Binding Source={StaticResource ConnectionsBridge}}" />
                        <ComboBoxItem>&lt;New...&gt;</ComboBoxItem>
                    </CompositeCollection>
                </ComboBox.ItemsSource>

                **<ComboBox.SelectedIndex>
                    <Binding Path="SelectedConnectionIndex"/>
                </ComboBox.SelectedIndex>**

            </ComboBox>
4

1 に答える 1

1

インデックス(int)またはアイテム(object)にバインドしていますか。あなたの例は、オブジェクトではなく、インデックスを示すプロパティにバインドします。

SelectedIndexバインディングのModeプロパティを設定する必要があります

<ComboBox SelectedIndex="{Binding SelectedConnectionIndex, Mode=TwoWay}">
</ComboBox>
于 2012-05-24T15:29:49.543 に答える