Click here to Skip to main content
13,092,310 members (58,303 online)
Rate this:
Please Sign up or sign in to vote.
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 data
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 10-Sep-11 10:53am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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 :-)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 14 Sep 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100