0
我正在尝试在WPF表单中编写我的第一个数据绑定实现。将参数传递给CollectionViews
我已经到了可以成功检索数据以填充所需条目的组合框的位置,但是我坚持要如何在给定组合框的当前选择的情况下填充相关ListView。
为了更好地解释我的问题,这是支持我的应用程序的当前视图。
class SchoolBookViewModel
{
public SchoolBookViewModel() { }
//Problem is here... How do I pass in the SelectedSchoolClassID?
public CollectionView ClassBookListEntries(Guid SelectedSchoolClassID)
{
return new CollectionView(SchoolQuoteList.GetSchoolClassQuoteListBySchoolClassID(SelectedSchoolClassID, 2011, "MyConnectionString"));
}
public CollectionView SchoolEntries
{
get
{
return new CollectionView(SchoolList.GetSchoolList("MyConnectionString"));
}
}
}
这是XAML
<StackPanel Height="449" HorizontalAlignment="Left" Margin="12,12,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="650" DataContext="{Binding}">
<Label Content="School:" Height="28" Name="lblSchoolName" Width="651" />
<ComboBox Height="23" Name="cmbSchoolNames" Width="644" DisplayMemberPath="SchoolName" ItemsSource="{Binding Path=SchoolEntries}" SelectedValuePath="SelectedSchoolClassID" SelectionChanged="cmbSchoolNames_SelectionChanged" />
<Label Content="Class booklist:" Height="29" Name="label1" Width="651" />
<ListView Height="163" Name="lblClassBookList" Width="645" ItemsSource="{Binding Path=ClassBookListEntries}" DisplayMemberPath="QuoteReference" />
</StackPanel>
而在Window_Loaded方法我称之为
stackPanel1.DataContext = new Views.SchoolBookViewModel();
难道我甚至在正确的轨道?任何指导将不胜感激。
现在,如果只有堆栈溢出的每个答案都做得很好。谢谢!我得说我正在努力与WPF(即使它的意思是更简单)PS:我已经注意到,大多数试图做类似的事情的代码使用INotifyPropertyChanged。你能解释为什么这个代码需要吗? – 2011-03-18 03:16:17