English 中文(简体)
失去选中的 Index 的 ComboBox
原标题:ComboBox losing SelectedIndex

我有一个问题, 我的组合框在关闭用户控制时会失去它的 选中 Index 值 。 视图模式仍然有它, 但视图会不断重置到 - 1 。 我理解, 绑定物品源代码和选中 Index 的顺序有问题, 但我并不直接约束物品源代码 。 基本上, 我试图为下面的绑定找到正确的语法 。

               </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>
最佳回答

您对索引( int) 或项目( object) 具有约束力。 您的示例对显示索引而非对象的属性具有约束力。

您应该设置选中 Index 的模式属性绑定

<ComboBox SelectedIndex="{Binding SelectedConnectionIndex, Mode=TwoWay}">
</ComboBox>
问题回答

暂无回答




相关问题
WPF Datagrid, Setting the background of combox popup

I would like to change the color of the popup background when using a DatagridComboboxColumn in the WPF Toolkit datagrid. I ve edited the Template for a normal Combobox and it works great for selected ...

How to insert ComboBox item into ListBox? [winforms]

The question is very simple, How to insert ComboBox selected item into ListBox using c#? I have tried with this: listbox.Items.Add(combobox.SelectedItem); and some other permutations but it always ...

How do I bind a ComboBox to a one column list

I ve seen how to bind a ComboBox to a list that has columns like this: ItemsSource="{Binding Path=Entries}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding Path=Entry}" But ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

热门标签