我有一個學生類作爲顯示如下綁定多個控件組合框中選擇
public class Student
{
public string Name { get; set; }
public string Operator { get; set; }
public IList<Subject> Subjects { get; set; }
}
現在我想這個學生給我窗口的三個控件的集合捆綁如下圖所示
<ComboBox Margin="12,28,0,0"
Name="cbStudents"
VerticalAlignment="Top"
ItemsSource="{Binding Path=PersonList}"
DisplayMemberPath="Name"
SelectedValuePath="Operator" />
<TextBox Margin="12,75,0,0"
Name="tbOperator"
VerticalAlignment="Top"
Text="{Binding ElementName=cbStudents,Path=SelectedValue}" />
<ComboBox Margin="12,123,0,0"
Name="cbSubjects"
VerticalAlignment="Top"
ItemsSource="{Binding ElementName=cbStudents, Path=SelectedValue}"
DisplayMemberPath="SubjectName" />
現在我的關注點是,每當我在cbStudentsthen中更改一個選擇時,其他控件也應該更改它們的相應值。在上面給出的代碼中,只要cbStudents中的選擇改變tbOperator中的文本正在改變,並且我也想爲cbSubjects實現相同的代碼。除了擁有cbStudents的SelectionChanged事件之外,有沒有辦法解決這個問題。
非常感謝您的回覆。有效 :) – Vikram