在控件/查询和演示元素之间移动数据的最新最佳方式是什么

发布于 2024-09-15 02:44:39 字数 642 浏览 5 评论 0原文

我有几个组合框选项,用户可以在 WPF 窗口上进行选择。每个组合框都通过 EDMX 绑定到不同的表。组合不会相互绑定。

我正在寻找主/详细功能。当用户选择任何组合框选择(主)时,从选择(参数)构建的查询结果(详细信息)应显示在窗口的数据网格部分中。

数据网格没有明确定义,因为它将包含不同的数据,具体取决于从中选择的组合框。因此,对于我正在使用的数据网格:

<StackPanel Grid.Row="1" Height="167" Name="stackPanel4" VerticalAlignment="Top" DataContext="{StaticResource tbl_MyGenericDataGridViewSource}">
            <DataGrid AutoGenerateColumns="True" Height="166" Name="dataGrid1" Width="760" ItemsSource="{Binding}" />
</StackPanel>

查询结果和数据网格之间的最佳数据缓存是什么?
我应该使用数据集吗?

这将是我可以在组合框选择事件或查询返回事件上绑定到数据网格的东西。我想利用 Framework 4.0 WPF 魔法来做到这一点。

I have several combobox choices which a user can select from on a WPF window. Each of those compbo boxes are bound to different tables through EDMX. The combos do not bind to eachother.

I'm looking for a master/detail functionality. When a user selects anyone of the combobox selections(master) a query results(details) built from the selection(parameter) should be displayed in a datagrid section of the window.

The datagrid is NOT explicitly defined as it will contain different data depending on which combobox was selected from. So for the datagrid I'm using:

<StackPanel Grid.Row="1" Height="167" Name="stackPanel4" VerticalAlignment="Top" DataContext="{StaticResource tbl_MyGenericDataGridViewSource}">
            <DataGrid AutoGenerateColumns="True" Height="166" Name="dataGrid1" Width="760" ItemsSource="{Binding}" />
</StackPanel>

What is the best data cache between the query results and the datagrid?
Should I be using a dataset?

This would be something I can bind to the datagrid on a combobox selection event or query return event.I want to do this taking advantage of Framework 4.0 WPF wizardry.

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

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

发布评论

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

评论(1

软糖 2024-09-22 02:44:39

我对 EDMX 一无所知。但要做到这一点,我将创建一个简单的视图模型类,该类公开 ParentDataViewChildDataViewText 属性,并填充它们的集合,然后执行如下操作:

<ComboBox x:Name="selectTable" 
          ItemsSource="{Binding {StaticResource TableCollection}"             
          DisplayMemberPath="Text"/>
<DataGrid ItemsSource="{Binding ElementName=selectTable, Path=SelectedItem.ParentDataView}"/>
<DataGrid ItemsSource="{Binding ElementName=selectTable, Path=SelectedItem.ChildDataView}"/>

您可能还可以绑定到 DataTable 对象的集合,并将子数据网格的 ItemsSource 上的绑定设置为类似 < code>SelectedItem.ChildRelations[0].ChildTable,但是如果表有多个子关​​系并且您不想使用第一个子关系,那么您就会有点搞砸了。

此外,在视图模型类中创建 DataView 可以让您在需要时轻松实现排序和过滤命令。

I know nothing of EDMX. But to do this, I'd create a simple view model class that exposed ParentDataView, ChildDataView, and Text properties, populate a collection of them, and then do something like this:

<ComboBox x:Name="selectTable" 
          ItemsSource="{Binding {StaticResource TableCollection}"             
          DisplayMemberPath="Text"/>
<DataGrid ItemsSource="{Binding ElementName=selectTable, Path=SelectedItem.ParentDataView}"/>
<DataGrid ItemsSource="{Binding ElementName=selectTable, Path=SelectedItem.ChildDataView}"/>

You could probably also just bind to a collection of DataTable objects, and set the binding on the child data grid's ItemsSource to a path like SelectedItem.ChildRelations[0].ChildTable, but then you'd be kind of screwed in the case where the table had multiple child relations and you didn't want to use the first one.

Also, creating DataViews in your view model class gives you an easy path to implementing sorting and filtering commands when the time comes.

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