Click here to Skip to main content
14,733,542 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I want understand binding in WPF. In code I have an ObservableCollection called _orders.

I work with Entity Framework and classes have all needed properties.
I want to display orders in DataGrid. In dataGrid I have declared columns with Binding like this:

<DataGridTextColumn Header="OrderID" x:Name="OrdersTabOrderIDColumn" Binding="{Binding OrderID}" Visibility="Hidden"/>


and in code I do this:

OrdersDataGrid.ItemsSource = _orders;


Is it right ? Can I already put this _orders inside xaml code?

Next step is binding textbox, ComboBox to the OrdersDataGrid.SelectedItem.
When I click on some row inside DataGrid I want to display item properties in TextBoxes and ComboBoxes.

Right now I handle event DataGridSelectionChanged, in event I check if selectedItem isn't null, and if isn't I manually rewrite properties to textboxes and comboBox.SelectedVale. ComboBox is binded inside code:

productsComboBox.ItemsSource = _products


When I want to save my changed order I have to read values from textboxes, comboboxes and write to object and then save it in database.

How can I do this automatically with binding?
Posted
Updated 26-Jan-15 4:25am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900