2012-03-19 5 views
0

В моем проекте я привязываю наблюдаемую коллекцию к datagrid. Каждый столбец У datagrid есть поле со списком, которое является связанным свойством и возвращает список строк. Выбранный элемент поля со списком связан с другим свойством моей наблюдаемой коллекции. Аксессор доступа отлично работает в поле со списком, но набор не работает. Мне нужно, чтобы работать, я должен сохранить изменения в своей базе данных.Почему ComboBox selectedItem не вызывает set accessor

Вот какая-то часть моего XAML

<DataGrid SelectedItem="{Binding SelectedPartProperty, Mode=TwoWay}" 
       ItemsSource="{Binding AllPartProperties}" AutoGenerateColumns="False" Grid.Row="1" Margin="416,6,302,0"> 
     <DataGrid.Columns> 
      <DataGridTextColumn Header="Name" Binding="{Binding PropertyName,Mode=TwoWay}" IsReadOnly="false"/> 
      <DataGridTemplateColumn Header="Data Type" IsReadOnly="false"> 
       <DataGridTemplateColumn.CellTemplate> 
        <DataTemplate> 
         <ComboBox SelectedItem="{Binding PropertyDataType, Mode=TwoWay}" 
          ItemsSource="{Binding DataType}" 
          Background="White" /> 
        </DataTemplate> 
       </DataGridTemplateColumn.CellTemplate> 
      </DataGridTemplateColumn> 

     </DataGrid.Columns> 
    </DataGrid> 

Моя главная модель вид

public ObservableCollection<PartPropertyViewModel> AllPartProperties 
    { 
     get 
     { 
      if (SelectedPartNumber == null) 
      { 
       _allProperties = new ObservableCollection<PartPropertyViewModel>(); 
       return _allProperties; 
      } 
      PartPropertyViewModel tempPartPropertyViewModel; 
      ObservableCollection<PartPropertyViewModel> newPartPropertyViewModel = new ObservableCollection<PartPropertyViewModel>(); 
      foreach (PartProperty p in SelectedPartNumber.PartNumberEntity.PartProperties) 
      { 
       tempPartPropertyViewModel = new PartPropertyViewModel(p); 
       newPartPropertyViewModel.Add(tempPartPropertyViewModel); 
      } 

      _allProperties = newPartPropertyViewModel; 
      return _allProperties; 
     } 
     set 
     { 
      _allProperties = value;    

     } 

    } 

Другой ViewModel

class PartPropertyViewModel : ViewModelBase 
{ 
    private PartProperty _partPropertyEntity;  
    private string _propertyDataType; 
    private string[] _dataType; 
    private PartParameterViewModel _partParameters; 

    public PartPropertyViewModel(PartProperty partProperty) 
    { 
     PartPropertyEntity = partProperty; 
     _partParameters = new PartParameterViewModel(partProperty); 
    } 

    //public PartPropertyViewModel() 
    //{ 
    // //PartPropertyEntity = new PartProperty();   
    //} 


    public PartProperty PartPropertyEntity 
    { 
     get 
     { 
      return _partPropertyEntity; 
     } 
     set 
     { 
      _partPropertyEntity = value; 
     } 
    } 
    public string PropertyName 
    { 
     get 
     { 
      if (PartPropertyEntity == null || PartPropertyEntity.ConfigurationProperty == null) 
       return ""; 
      else 
       return PartPropertyEntity.ConfigurationProperty.chrCPProperty; 
     } 
     set 
     { 
      PartPropertyEntity.ConfigurationProperty.chrCPProperty = value; 
      OnPropertyChanged("PropertyName"); 
     } 
    } 

    public string[] DataType 
    { 
     get 
     { 
      _dataType = new string[] { "Number", "String"};     
      return _dataType; 
     } 
     set 
     { 
      _dataType = value; 
      OnPropertyChanged("DataType"); 
      OnPropertyChanged("PropertyDataType"); 
     } 

    } 
    public string PropertyDataType 
    { 
     get 
     { 
      if (PartPropertyEntity == null || PartPropertyEntity.ConfigurationProperty == null) 
       return ""; 

      if (PartPropertyEntity.ConfigurationProperty.bitCPIsNumeric) 
       _propertyDataType = DataType[0]; 
      else 
       _propertyDataType = DataType[1]; 
      return _propertyDataType; 
     } 
     set 
     { 
      _propertyDataType = value; 

      if (String.Compare(value,"Number") == 0) 
       PartPropertyEntity.ConfigurationProperty.bitCPIsNumeric = true; 
      else 
       PartPropertyEntity.ConfigurationProperty.bitCPIsNumeric = false; 

      OnPropertyChanged("PropertyDataType"); 
     } 
    } 



    public PartParameterViewModel PartParameters 
    { 
     get 
     { 
      return _partParameters; 
     } 
    } 

}//end of class 

ответ

0

Вы связываясь с строковый массив

public string[] DataType 

Строка не имеет свойства PropertyDataType, и я сомневаюсь, что get также называется.

Необходимо связать с коллекцией, как Список или ObservableCollection

+0

Gotcha .. сделаю это. – IamaC

Смежные вопросы