Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm writing my first WPF application. The main window has a datagrid that is bound to a datatable that that contains all but one field from the datasource. The remaining field from the datasource contains one or more of the following: txt, html, or rtf. The format of the data in this field is like so:

<!txt!> <--indicates type of data that follows
<*filename*> <-- name of the file this data came from.
text data
<!rtf!>
<*filename*>
rtf data
<!html!>
<*filename*>
html data

When a row is selected, a RowDetails panel is shown with a TabControl. Here's where my question comes in.

Upon the row selection, I'd like to query the datasource for this field and for each data type indicator found in the data, create a Tab in the TabControl with the appropriate viewer (TextBox, RichTextBox, or WebBrowser) as the Tab's child and the Tab Header as the filename.

I'm looking for guidance. Is this possible with Xaml & converters or controllers? I've read several articles but have been unable to devise a way to implement my particular need. Or maybe this could be done strictly with code but I've not been successful accessing the tab control in the RowDetails panel.

Hoping someone can get me pointed in the right direction.
Posted

1 solution

Create a property in the CodeBehind or ViewModel. Use that property and create a Binding to the DataGrid's SelectedItem (you have probably done this already).

Then the SelectedItem property should hold a row as defined in the ItemsSource.
If the rows are known classes with known properties, this is simple. If it's a DataTable with DataRows, it's still quite possible but maybe a little more hazzle.

In the TabControl, create a Binding to the "ItemsSource" (for the TabControl) to the SelectedItem. Then use a Converter with a StaticBinding to a class implementing the "IValueConverter".

The "value" property in the converter's "Convert" method should then be a the SelectedItem.

Parse the SelectedItem properties or columns, create an ObservableCollection<Control> or ObservableCollection<TabItem>. If you create a collection of Control, you may have to define an "ItemTemplate" for the TabControl.

Then add all the controls you need to the colelction and return the whole collection in the converter's "Convert" method.

I hope I understood the problem/question :-)
 
Share this answer
 

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