C#/ WPF:将Datagrid中的Combobox ItemSource绑定到DataContext外部的元素

我想做以下事情:

public List PreLoadedUserList { get; set; } public List SomeDataRowList { get; set; } public class Users { public int Age { get; set; } public string Name { get; set; } } public class SomeDataRowList { public int UserAge { get; set; } 

现在我的(WPF Toolkit)DataGrid看起来像这样:

    

现在我的问题是,PreLoadedUserList在ItemSource(SomeDataRowList)之外,我不知道如何绑定到它之外的东西。 我真正想要它: – 在ComboBox中显示PreLoadedUserList – 将(RowEntries)SelectedItem.UserAge的值设置为所选ComboboxItem.Age的值

如果我的解释太奇怪,请告诉我:-)

谢谢,干杯

开始了 :-)

        

希望这也可以帮助别人。

干杯

如果RowEntries是一个自定义类,只需给它一个PreLoadedUserList的引用。 然后,每个实例都有一个指向它的指针,您可以在绑定中使用它。

只是一个建议,像Users和RowEntries这样的类名称表明它们是集合,但你的用法看起来就像是项目而不是集合。 我会使用单数名称来避免混淆。 我会做这样的事情

 public List PreLoadedUserList { get; set; } public List SomeDataRowList { get; set; } public class User { public int Age { get; set; } public string Name { get; set; } } public class RowEntry { public int UserAge { get; set; } public List PreLoadedUserList { get; set; } } // at the point where both PreLoadedUserList is instantiated // and SomeDataRowList is populated SomeDataRowList.ForEach(row => row.PreLoadedUserList = PreLoadedUserList);