我有這兩個組合框綁定到2個不同的數據庫表。首先必須與動物類(例如爬行動物,哺乳動物,兩棲動物等)一欄列表和其他有兩個列動物名稱及其各自的動物類(例如蜥蜴 - 爬行動物,蛇 - 爬行動物,狗 - 哺乳動物,青蛙 - 兩棲動物)。現在我想要的是,當我選擇組合框1中的項目時,組合框2應該具有與組合框1中選擇的項目相匹配的動物的各個列表以及每個動物的相應動物類別。一個組合框依賴於WPF中的其他組合框
這裏是我做了什麼至今
<ComboBox Grid.Column="2" Grid.Row="4" Margin="3,1,3,1"
Name="comboBox1"
ItemsSource="{Binding Source={StaticResource NameListData}, Path=Animal}"
Selectionchanged="comboBox1_Selectionchanged" />
<ComboBox Grid.Column="2" Grid.Row="5" Margin="3,1,3,1"
Name="comboBox2"
ItemsSource="{Binding Source={StaticResource NameListData}, Path=Stream}" />
的selection_changed功能
private static string aa;
private void comboBox1_Selectionchanged(object sender, SelectionchangedEventArgs e)
{
aA = comboBox1.SelectedItem.ToString();
}
public static string aA
{
get { return aa; }
set { aa = value; }
}
到2個組合框結合並位於MainViewModel類集合
DataClasses1DataContext dc = new DataClasses1DataContext();
public List<string> Animal
{
get
{
List<string> facult = new List<string>();
foreach (var a in dc.Faculties)
{
facult.Add(a.Animal1.ToString());
}
return facult;
}
}
string selection;
public List<string> Stream
{
get
{
selection = Schooling.Pages.NewStudentGeneral.aA;
List<string> stream = new List<string>();
var q = from c in dc.Streams where c.faculty ==selection select c;
foreach (var b in q)
{
stream.Add(b.stream1);
}
return stream;
}
}
這裏的選擇字符串沒有得到在combobox1 b中選擇的值因爲每當我硬編碼和指定下面的聲明中的選擇部分
1 var q = from c in dc.Streams where c.faculty =="Reptiles" select c;
將給各個動物的爬行動物。
我猜如果選擇變量獲得了combobox1的選定值,我的問題已解決。或者我在這裏做錯了什麼?請幫忙。