toadzky 0 Junior Poster in Training

I am writing a flat-file database app using SQLite. That part works just fine, but the GUI not so much.

The issues are arising in the bindings. I have a list of accounts displayed in a datagrid. The datagrid has its ItemsSource set to a List<Accounts> collection. That works fine.

Only the basic information is displayed by the datagrid. I am using an accordion control to display the rest of the information for the selected account.

I want everything to update automatically when the user selects a row on the datagrid. I would like it to do it with just databindings and datacontext so I don't have to write a bunch of event handling code to rebind / update every field with every new selection.

Right now, I have to set things manually. I get the Account object from the datagrid like this:

((Account) datagrid.SelectedGridItem.Row.DataItem)

which retrieves the object and casts it. Since I have to cast it, I don't think I can use the XAML bindings I keep seeing in examples (if I'm wrong PLEASE tell me) that look like this:

<StackPanel DataContext="{Binding Source=datagrid....}">
   <TextBox Text="{Binding Path=Customer.Name}" />
</StackPanel>

or something similar.

Thanks for any help you can give.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.