2012-05-24 4 views
1

내 콤보 상자가 UserControl 닫을 때 SelectedIndex 값을 잃어 버리는 문제가 있습니다. ViewModel은 여전히 ​​그것을 가지고 있지만보기는 -1로 재설정을 유지합니다. ItemSource 및 SelectedIndex를 바인딩하는 순서에 문제가 있음을 알고 있지만 ItemSource에 직접 바인딩하지 않습니다. 기본적으로 아래 바인딩에 대한 올바른 구문을 이해하려고합니다.ComboBox가 SelectedIndex를 잃는 중

   </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> 
+0

바인딩 지금 숀의 반응에 올바른 감사하지만 지수는 여전히 재설정됩니다 밝혀 바인딩 selectedIndex의의 모드 속성을 설정해야합니다. – nathantruant

답변

1

색인 (int) 또는 항목 (개체)에 바인딩하고 있습니까? 귀하의 예제는 개체가 아니라 인덱스를 나타내는 속성에 바인딩됩니다.

당신은

<ComboBox SelectedIndex="{Binding SelectedConnectionIndex, Mode=TwoWay}"> 
</ComboBox> 
+0

Ooops, SelectedIndex를 의미합니다. – nathantruant

+0

CompositeCollection 내에서 ItemSource 바인딩이 발생하기 때문에 콤보 상자 수준의 SelectedIndex에 바인딩 할 수 없습니다. 그것이 핵심입니다. 위의 작업을 수행하는 방법을 알아야합니다. 태그 내부에 의 중첩 부분이 있습니다. – nathantruant

관련 문제