请帮助我弄清楚如何在 WPF 的 DataGrid 中使用 ComboBoxColumn。我正在尝试创建一个设备列表,其中每个设备在“日志”字段中都有动态状态列表。
<DataGrid AutoGenerateColumns="False" Margin="12,6,12,12" Name="dataGrid1" Grid.Row="1" SelectionUnit="FullRow">
<DataGrid.Columns>
...
<DataGridComboBoxColumn Header="Log"
ItemsSource="{Binding log, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Device}}}"/>
</DataGrid.Columns>
</DataGrid>
public partial class MainWindow : Window
{
public ObservableCollection<Device> devices;
...
}
public MainWindow()
{
...
dataGrid1.ItemSource = devices;
}
public class Device : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public Device() {log = new ObservableCollection<string>();}
...
private ObservableCollection<string> _log;
public ObservableCollection<string> log { get { return _log; }
set { _log = value; OnPropertyChanged("log"); } }
}
您能否分享任何建议:如何在每个对象的数据网格列表“日志”中的每个组合框中显示?