2010-07-14 2 views
0

아래 그림과 같이 ItemTemplate을 사용하는 ComboBox가 있습니다. 어떻게 든 항목 템플릿에 정의 된 텍스트 상자의 Text 속성은 바인딩에서 연결이 끊기고 선택한 항목이 변경되면 업데이트되지 않습니다.ComboBox의 ItemTemplate 컨트롤이 바인딩을 잃습니다.

ComboBox.ItemsSource는 CatheterDefinition 개체 목록 인 DependencyProperty에 바인딩됩니다. ComboBox.SelectedItem은 단일 CatheterDefinition 개체 인 DependencyProperty에 바인딩됩니다.

<ComboBox 
    AutomationProperties.AutomationId="CatheterInfoModelFieldID" 
    VerticalAlignment="Center" HorizontalAlignment="Stretch" 
    ItemsSource="{x:Static PumpAndCatheter:CatheterInfoViewModel.CatheterModelDefinitions}" 
    SelectedItem="{Binding ElementName=UserControl, Path=ViewModel.SelectedCatheterModel, Mode=TwoWay, NotifyOnSourceUpdated=True}" 
    SourceUpdated="HandleModelSourceUpdated"> 
    <ComboBox.ItemContainerStyle> 
    <!-- A style used to set the AutomationID based on the item goes here --> 
    </ComboBox.ItemContainerStyle> 
    <ComboBox.ItemTemplate> 
    <DataTemplate> 
     <!-- This line below is the location of the problem --> 
     <TextBlock Text="{Binding Converter={StaticResource CatheterModelDefinitionToStringConverter}}"> 
     <!-- A style used to set the AutomationID based on the item goes here --> 
     </TextBlock> 
    </DataTemplate> 
    </ComboBox.ItemTemplate> 
</ComboBox> 

I가 매우 이상한 행동을 (내가 같은 동작을 코드의 초기 개발하는 동안 몇 시간을 보았지만, 수동으로 재현 할 수 없습니다) 생성하는 자동화 된 테스트 -이 선택을 재현 테스트를 항목이 ComboBox를 형성 한 다음 응용 프로그램의 다른 부분으로 이동하여 데이터 모델에서이 변경 사항을 저장하는 일부 작업을 수행합니다. 이 ComboBox가있는 화면으로 테스트가 돌아 오면 ComboBox에서 다른 항목을 선택하려고 시도합니다. SelectedItem이 변경되고 바인딩 할 값이 변경되지만 ComboBox의 텍스트는 변경되지 않습니다 - 텍스트 상자의 Text 속성에 대한 바인딩이 깨졌습니다 (또는 무언가) ... 바인딩이 여전히 실행됩니다 (변환기는 선택이 변경되고 올바른 값으로 변환 될 때 계속 실행되지만 텍스트 속성은 절대로 업데이트되지 않습니다.

생각하십니까? (이 예제는 거대한 응용 프로그램이므로 제공 할 수 없으며 알고있는 한 테스트에서 재생산 할 수 있습니다)

+0

잘 모르겠지만 SelectedItem이 아니라 SelectedValue에 바인딩해야합니다. –

답변

0

대부분의 경우 끊어진 바인딩은 전화를 걸지 않거나 올바르게 호출하지 않아서 발생합니다. OnPropertyChanged ("PropName") 메서드.

기본 구현을 보지 않고도이 문제의 원인 일 가능성이 큽니다.

+0

콤보 상자가 바인딩되는 속성은 종속성 속성입니다. OnPropertyChanged를 호출 할 필요는 없습니다. 또한 텍스트 상자 대신 레이블을 사용하도록 항목 템플릿을 변경했습니다. 흥미롭게도 Label.Content 속성이 올바르게 설정되었지만 Textbox.Text 속성이 여전히 손상되었습니다. – Andy

+0

또한 화면을 떠날 때 연결 끊김이 발생할 수 있다고 생각합니다.이 사실을 확인하지는 못했지만 이전에 생각했던 것보다 먼저 발생할 수 있습니다. – Andy

+0

중첩 된 뷰 모델이 DependencyProperty입니까? –