对不起,如果我的问题已经得到解答,我很可能没有使用正确的搜索条件。假设我有两个 `ObservableCollections。第一个是问题:
private ObservableCollection<Question> _questions = new ObservableCollection<Question>();
public ObservableCollection<Question> Questions
{
get { return _questions; }
set
{
if (value != _questions)
{
_questions = value;
OnPropertyChanged("Questions");
}
}
}
问题类看起来像:
public class Question : INotifyPropertyChanged
{
public Question()
{
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private int _no = -1;
public int No
{
get
{
return _no;
}
set
{
if (_no != value)
{
_no = value;
OnPropertyChanged("No");
}
}
}
private int _corespondingQuestionNo = -1;
public int CorespondingQuestionNo
{
get
{
return _corespondingQuestionNo;
}
set
{
if (_corespondingQuestionNo != value)
{
_corespondingQuestionNo = value;
OnPropertyChanged("CorespondingQuestionNo");
}
}
}
}
第二个是 的集合QuestionElements
,几乎相同,但它有No
和string Title
。两者都有的原因是,根据语言设置,我们将在DataGrid
for Title
eachCorespondingQuestionNo
中显示正确的语言。目前我的 DataGrid 看起来像:
<DataGrid x:Name="questionsDataGrid"
ItemsSource="{Binding ElementName=casesDataGrid, Path=SelectedItem.Questions, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
>
<DataGrid.Columns>
<DataGridTextColumn
Binding="{Binding Path=No, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
显示Title
来自ObservableCollection<QuestionElements>
No ==的 DataGridTextColumn 应该如何CorespondingQuestionNo
?