4
我在列表視圖中遇到了數據綁定問題。我有兩個類別: - 交易 - 基板 交易具有Substrate的屬性,Transactiona保存在數據庫中。在程序開始時,我想將所有事務加載爲列表並在ListView中顯示它們。襯底的每種可能性都應顯示在組合框中,其中選擇了實際的襯底。ListView中的Wpf Combobox綁定
從來就嘗試過這樣的 XAML
<ListView.View>
<GridView>
<GridViewColumn Header="Menge">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Amount}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Substrate">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox
ItemsSource="{Binding ElementName=InternTransaction, Path=SubstrateList}"
DisplayMemberPath="Description"
SelectedValuePath="SubstrateID"
SelectedItem="{Binding Path=Substrate.SubstrateID}">
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
代碼隱藏
public partial class UCInternTransaction : UserControl
{
#region Attribute
private BsCBTTransactionController mTransactionController;
private ObservableCollection<BsCBTSubstrate> mSubstrateList;
#endregion
public UCInternTransaction()
{
InitializeComponent();
//Load Transactions
this.mTransactionController = WpfBioGas.Core.BsCAppFactory.getInstance().getCBTTransactionController();
this.mTransactionController.loadTransactions();
this.DataContext = this.mTransactionController.TransactionList;
loadData();
}
private void loadData()
{
//Load Substrate and bind to CBSubstrate
this.mSubstrateList = new ObservableCollection<BsCBTSubstrate>();
foreach (BsCBTSubstrate sub in WpfBioGas.Core.BsCAppFactory.getInstance().getBTFacade().BsBTSubstrate.loadAll())
{
this.mSubstrateList.Add(sub);
}
}
public ObservableCollection<BsCBTSubstrate> SubstrateList
{
get { return this.mSubstrateList; }
}
}
的問題是列表的所有條目顯示在列表視圖,併爲每一行所有的可能性底物在Combobox中。但只有Listview的第一行選擇了實際的Substrate。