繁体   English   中英

如何在devexpress组合框BarItem中设置SelectedItem属性的值?

[英]How to set the value of the SelectedItem property in devexpress combobox BarItem?

这是一个示例组合框,其中的所有功能均正常运行,并且所选值根据CurrentPlanSet的更改而有所不同。

       <dxe:ComboBoxEdit ItemsSource="{Binding PlanSets, Mode=TwoWay}" 
                               DisplayMember="Name" 
                               ValueMember="Name"
                               SelectedItem="{Binding CurrentPlanSet, Mode=TwoWay}"
                               />

在此示例中,所选值不会根据CurrentPlanSet的更改而更改。

<dxb:BarEditItem Content="Plan Sets" EditWidth="350">
                <dxb:BarEditItem.EditStyle>
                    <Style TargetType="{x:Type dxe:ComboBoxEdit}">
                        <Setter Property="SelectedIndex" Value="{Binding     CurrentPlanSet, Mode=TwoWay}"/>
                    </Style>
                </dxb:BarEditItem.EditStyle>
                <dxb:BarEditItem.EditSettings  >
                    <dxe:ComboBoxEditSettings ItemsSource="{Binding PlanSets, Mode=TwoWay}" ValueMember="Id" DisplayMember="Name" />
                </dxb:BarEditItem.EditSettings>
            </dxb:BarEditItem>

如何在第二个代码示例中正确设置SelectedItem属性的值?

SelectedIndex与SelectedItem不同。 这与默认的WPF控件相同。

SelectedIndex是CollectionItem的索引,您已选择/设置了所选内容(整数)。 SelectedItem是Item对象本身。

示例:让我们看一下这个Collection: new ObservableCollection<string>(){ "String1", "String2", String3"}如果SelectedItem是/应该为String1,则SelectedIndex为0。

所以只要更换

<Setter Property="SelectedIndex" Value="{Binding CurrentPlanSet, Mode=TwoWay}"/>

<Setter Property="SelectedItem" Value="{Binding CurrentPlanSet, Mode=TwoWay}"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM