2016-08-18 16 views
0

これは、すべてがうまく動作し、選択された値がCurrentPlanSetの変更によって異なるComboboxの例です。devexpressコンボボックスでSelectedItemプロパティの値を設定する方法BarItem?

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

2番目のコード例でSelectedItemプロパティの値を正しく設定する方法はありますか。

答えて

1

SelectedIndexはSelectedItemと同じではありません。 これは既定のWPFコントロールと同じです。

SelectedIndexはCollectionItemのインデックスで、選択済み(選択済み)です(整数)。 SelectedItemはItemオブジェクト自体です。

例: は、このコレクションを取ることができます:new ObservableCollection<string>(){ "String1", "String2", String3"} のSelectedItemがある場合は/文字列1 SelectedIndexをがだから

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

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

を交換0

であるべきです

関連する問題