使用参数绑定 WPF 数据网格中的组合框

发布于 2024-11-13 08:45:20 字数 211 浏览 4 评论 0原文

我有一个 DataGrid,模板列内有一个组合框。在该屏幕的其他地方,用户可以从单独的控件中进行“客户”选择。为了填充数据网格中的组合框,除了网格中每行的其他信息之外,我还需要将所选客户作为参数传递。

基本上...网格包含零件信息,组合框项目基于以下内容的组合:所选客户、零件编号和制造商。每行的组合框可能有不同的源列表。有没有办法可以在 XAML 中绑定该组合框的 ItemsSource?

I have a DataGrid with a combobox inside a template column. Elsewhere on this screen, the user makes a 'customer' selection from a separate control altogether. In order to populate the comboboxes in my datagrid, I need to pass in that selected customer as a parameter, in addition to other information from each row in the grid.

Basically... the grid contains part information, and the combobox items are based on a combination of the following: selected customer, part number, and manufacturer. Each row's combobox can potentially have a different source list. Is there a way I can bind the ItemsSource for that combobox in XAML?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

药祭#氼 2024-11-20 08:45:20

我可能没有正确理解,但您可能有一个包含所有这些信息的对象,并将其绑定到组合框。

public class ContextualInfo
{
    public Customer Customer { get; set; }
    public int PartNumber { get; set; }
    public Manufacturer Manufacturer { get; set; }
}

回复评论。

让从查询返回的行也位于上面提到的 ContextualInfo 中怎么样?然后您可以将 itemsource 绑定到它。您可以在 ContextualInfo 类的构造函数中运行查询。

I may not understand correctly, but you could possibly have an object that contains all that information together, and bind that to the combo box.

ie

public class ContextualInfo
{
    public Customer Customer { get; set; }
    public int PartNumber { get; set; }
    public Manufacturer Manufacturer { get; set; }
}

In reply to comment.

How about having the rows returned from the query to also be in the ContextualInfo mentioned above? You can then bind the itemsource to that. You could potentially run the query in the constructor for the ContextualInfo class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文