开发者

What is the latest greatest way to move data between controls/queries and presentation elements

开发者 https://www.devze.com 2023-01-12 07:21 出处:网络
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 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 datagri开发者_开发技巧d on a combobox selection event or query return event.I want to do this taking advantage of Framework 4.0 WPF wizardry.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消