【发布时间】:2017-10-16 10:47:57
【问题描述】:
我已经将 ListCollectionView 作为“ListCollectionView1”提供给 Grid 和 inGrid,我使用了 DataGrid。 “ListCollectionView1”包含两个可观察的集合。 “ObservableCollection1” DataGrid 和另一个可观察集合作为“ObservableCollection2”,它在“ObservableCollection1”可观察集合中作为 Itemsource 到 DataGridComboBoxColumn 。 并且作为 SelectedValueBinding 我使用 Property as "a" from "ObservableCollection1" 但我没有得到 DataGridComboBoxColumn 中的值
<Grid DockPanel.Dock="Bottom" DataContext="{Binding ListCollectionView1>
<DataGrid
ColumnWidth="130"
CanUserAddRows="True"
AutoGenerateColumns="False"
ItemContainerStyle="{StaticResource DataGridRowContentStyle}"
ItemsSource="{Binding ObservableCollection1 }"
CanUserDeleteRows="False">
<DataGridComboBoxColumn Header="Labour" ItemsSource="{Binding Path=ObservableCollection2 , RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" SelectedValueBinding="{Binding Id}" SelectedValuePath="Id" DisplayMemberPath="Id" HeaderStyle="{StaticResource DataGridHeaderStyle}"/>
</DataGrid>
</Grid>
在我的 viewModel 中可观察的集合和 listcollectionview 是
private ListCollectionView _ListCollectionView1;
public ListCollectionView ListCollectionView1
{
get { return _ListCollectionView1; }
set
{
this._ListCollectionView1= value;
OnPropertyChanged("ListCollectionView1");
}
}
public ObservableCollection<Model_ObservableCollection1> ModelObservableCollection1
{
get { return new ObservableCollection<Model_ObservableCollection1>(ViewModel.AllDataCollactions.AllTransactionsDetails.Where(s => s.TransactionsID.Equals(TransactionsID))); }
}
public ObservableCollection<Model_ObservableCollection2> Model_ObservableCollection1
{
get { return new ObservableCollection<Model_ObservableCollection1>(ViewModel.AllDataCollactions.AllTransactionsDetails.Where(s => s.TransactionsID.Equals(TransactionsID) && s.IsJama)); }
}
【问题讨论】:
-
从您的代码看来,
ListCollectionView1不包含两个可观察的集合,即ObservableCollection1和ObservableCollection2 -
没关系,他将源指向 ViewModel 的 UserControl。
标签: wpf xaml data-binding