我正在使用WPF,MVVM,DevExpress。 我试图用4列创建网格控制。 Cloumns 0和1是ComboBoxEdit。
注意:我使用col 0中的comboBoxEdit结果在Col 1中填充ComboBoxEdit。
我的问题是所有行中的comboboxEdit Col 1中的项目总是基于最后一行中存在的comboxBoxEdit Col 0。换句话说,我在所有行中的comboBoxEdit 1中始终具有相同的项目。
我如何实现目标。
在我的代码下面:
MyView.xaml
<dxg:GridControl x:Name = "FilterGridControl" AutoGenerateColumns = "AddNew" ItemsSource = "{Binding Path=FilterList, Mode=TwoWay}" EnableSmartColumnsGeneration = "True" SelectionMode = "Row" SelectedItems = "{Binding SelectedFilter, Mode=TwoWay}">
<dxg:GridControl.Columns>
<dxg:GridColumn Header = "Table" FieldName = "Table" HorizontalHeaderContentAlignment = "Center">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:ComboBoxEdit x:Name = "PART_Editor" IsTextEditable = "False" ItemsSource = "{Binding DataContext.FilterTables, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" SelectedItem = "{Binding DataContext.SelectedFilterTables, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"></dxe:ComboBoxEdit>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
<dxg:GridColumn Header = "Table Field" FieldName = "TableField" HorizontalHeaderContentAlignment = "Center" SortOrder = "Ascending" SortIndex = "0">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:ComboBoxEdit x:Name = "PART_Editor" IsTextEditable = "False" ItemsSource = "{Binding DataContext.FilterColumns, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" ValueMember = "Name" DisplayMember = "Name" EditValue = "{Binding DataContext.SelectedFilterColumns, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"></dxe:ComboBoxEdit>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
<dxg:GridColumn Header = "Name" FieldName = "Name" HorizontalHeaderContentAlignment = "Center">
<dxg:GridColumn.EditSettings>
<dxe:ComboBoxEditSettings IsTextEditable = "False" ItemsSource = "{ Binding EnumNameFilter}"></dxe:ComboBoxEditSettings>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
<dxg:GridColumn FieldName = "Value" HorizontalHeaderContentAlignment = "Center"/>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView Name = "view" AllowPerPixelScrolling = "False" ShowTotalSummary = "True">
<i:Interaction.Behaviors>
<utilities:FocusNullRowBehavior/>
</i:Interaction.Behaviors>
</dxg:TableView>
</dxg:GridControl.View>
MyViewModel.cs:
public string SelectedFilterTables {
get {
return _selectedFilterTables;
}
set {
this._selectedFilterTables = value;
InitialiseFilterColumns();
}
}
public void InitialiseFilterColumns() {
if (_selectedFilterTables != null) {
_selectedFilter = new FilterDefinition();
_selectedTable = null;
_selectedFilter.TableField = null;
_selectedFilter.Value = null;
_filterColumns = null;
_selectedTable = _tables.First(x = > x.Name == _selectedFilterTables);
_filterColumns = new ObservableCollection < Column > (_selectedTable.Columns.ToList());
OnPropertyChanged("FilterColumns");
}
}
提前谢谢。
答案 0 :(得分:0)
我不清楚问题是什么。我建议您在VM中创建属性,如:
public IEnumerable<FilterColumns> FilterColumnsCollection
{
get { return FilterList.LastOrDefault().FilterColumnsCollection} set {}
}