wpf - 动态绑定 DataGridComboBox 列
问题描述
我目前正在开发一个小型 wpf 组件,但从 2 天以来,我一直在与 DataGrid 中的一个奇怪问题作斗争。我尝试重新加载 DataGridComboBoxColumn 的 ItemSource。无法将 xaml 中的此列绑定到 ObservableList
我的 .xaml :
<DataGrid Grid.Row="3" Height="auto" Margin="0, 15, 0, 0" x:Name="mapAttributesTable" ColumnWidth="Auto"
SelectedIndex="0" ItemsSource="{Binding LinkedItems, Mode=TwoWay}" SelectedItem ="{Binding Path=CurrentColumnObject, Mode=TwoWay}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridComboBoxColumn x:Name="comboBox_TableFields" Header="TableFields" ItemsSource="{Binding Path=DataContext.Fields, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="{x:Type ComboBox}">
<EventSetter Event="SelectionChanged" Handler="ComboBoxColumn_SelectionChanged"/>
<Setter Property="IsEditable" Value="True" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
<DataGridTextColumn Header="JmsSubClass" Binding="{Binding Path= JmsSubClass}"/>
<DataGridTextColumn Header="JmsFieldName" Binding="{Binding Path=JmsFieldName}"/>
</DataGrid.Columns>
</DataGrid>
我背后的代码:
public IMap SelectedItem
{
get { return _selectedItem; }
set
{
if (value != null)
{
_selectedItem = value;
this.Items = new ObservableCollection<ILink>(SelectedItem.Links);
OnPropertyChanged();
this.Fields = new ObservableCollection<string>(SelectedDataMapItem.TableFields);
OnPropertyChanged("Fields");
}
}
}
private ObservableCollection<ILink> _items = new ObservableCollection<ILink>();
/// <summary>
/// Holds each created entry
/// </summary>
public ObservableCollection<ILink> Items
{
get { return this._items; }
set
{
if (value != null)
{
this._items= value;
}
}
}
/// <summary>
///
/// </summary>
private ILink _currentColumnObject;
/// <summary>
///
/// </summary>
public ILink CurrentColumnObject
{
get { return _currentColumnObject; }
set
{
if (value != null)
{
this._currentColumnObject = value;
OnPropertyChanged();
}
}
}
private ObservableCollection<string> _fields = new ObservableCollection<string>();
public ObservableCollection<string> Fields
{
get
{
return _fields;
}
set
{
if (value != null)
{
this._fields = value;
}
}
}
如果任何人(开发人员)有一个想法,解决这个问题会很好。
此致
解决方案
推荐阅读
- javascript - 如何在 Vue.js 中获取对象键值
- amazon-web-services - AWS SSH 连接超时
- c++ - 为什么移动 ios_base::sync_with_stdio(false), cin.tie(NULL) 会导致内存错误?
- unity3d - 为什么相同的材料会对模型产生不同的影响
- c# - 如何解决“错误:rzc discover exited with code 150”
- c# - 这在参数类型中意味着什么。这叫什么?
- javascript - 改进基于 `IntersectionObserver` 的延迟加载实现
- testing - 如果客户报告生产中的缺陷但您无法始终如一地重现它,您将如何报告该问题?
- unit-testing - 如何运行 ejabberd 测试并在 erlang 中编写新的单元测试?
- java - 如所述,在自定义网络中使用什么距离度量进行遍历?