2012-05-06 4 views
0

모든 테이블 및 SQL 데이터베이스를 표시 할 수있는 ComboBox를 편집 할 수 없습니다.편집 가능한 WPF ComboBox가 PropertyChanged를 실행하지 않습니다.

<ComboBox Grid.Column="1" 
         Grid.Row="2" 
         Height="23" 
         Margin="3,3,3,3" Name="cbLogTable" VerticalAlignment="Top" 
         ItemsSource="{Binding}" 
         TextSearch.TextPath="TABLE_NAME" 
         SelectedValue="{Binding Path=LogTable, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True}" 
         > 
       <ComboBox.ItemTemplate> 
        <DataTemplate> 
         <StackPanel> 
          <TextBlock Text="{Binding Path=TABLE_NAME}"/> 
         </StackPanel> 

        </DataTemplate> 
       </ComboBox.ItemTemplate> 
      </ComboBox> 
포함하는 UserControl을의 속성은 또한 다음과 같습니다과

는에서 INotifyPropertyChanged를 구현합니다

public string LogTable 
    { 
     get 
     { 
      return _logTable; 
     } 
     set 
     { 
      if (_logTable == value) return; 
      _logTable = value; 
      OnPropertyChanged("LogTable"); 
     } 
    } 

나는 다음과 같은 데이터가 콤보 상자 채우기 위해 바인딩을 사용

private void UpdateLogTable() 
    { 
     var connection = new SqlConnection(_connectionString); 
     connection.Open(); 
     DataTable t = connection.GetSchema("Tables"); 
     cbLogTable.DataContext = t; 
     connection.Close(); 
    } 

하지만 돈을 ComboBox의 선택된 값을 변경하는 것에 대한 PropertyChanged 알림을받지 못합니다. 내 잘못은 어디 있니? SelectedValue의 결합에서

+0

'LogTable'이 (는) 의존성 속성입니까? (UI 스레드의 'SqlConnection'을 제외하고) – Vlad

+0

여기서 propertychanged 이벤트를 트랩하려고합니까? –

답변

2

:

그렇지 않으면, 바인딩 (DataContext를 콤보입니다), 그리고 자동으로 실패 DataTable 유형에 LogTable 재산을 찾고
SelectedValue="{Binding Path=LogTable, 
         UpdateSourceTrigger=PropertyChanged, 
         Mode=TwoWay, 
         ValidatesOnDataErrors=True, 
         RelativeSource={RelativeSource FindAncestor, 
             AncestorType={x:Type UserControl}}}" 

.

관련 문제