Coffeehouse Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

OK WPF gurus, help me out here...

Back to Forum: Coffeehouse
  • User profile image

    I've been struggling creating a WPF TreeListView control for some time now. Coming from WinForms I'm trying to learn WPF but I find I get stuck on things that should really be easy. This is what I need to do:

    • Create a TreeListView derived from a ListView
    • Have two GridViewColumn templates that are automatically selected, one for the first column only, the second for the second and subsequent columns.
    • Be able to add/remove columns and items at runtime.
    • Have a TreeListViewItem derived from ListViewItem.
    • Have an IValueConverter or IMultiValueConverter class that can convert the row/column on demand. Right now I have a ContentControl so the converter can then stick whatever it wants in that cell.
    • It is OK if the columns use an ObservableCollection.

    My biggest problem up until now is how to tell in the converter what the current column is. Since the columns are dynamically generated (number of columns and column names are not known at compile time). So I've been struggling to get this working.

    Any help with this?

  • User profile image

    At first glance, it seems you're not using a converter correctly. The point of a converter is to convert the data to and from its intended visual representation. It looks like you're trying to use it to convert UI objects to other UI objects.

    What are the Column templates? What you really want to do is derive from GridViewColumn and handle the Grid's AutoGeneratedColumn event to replace the column that's being generated with your custom, templated column. That way, you'll know exactly what column is being generated and you can override the column with your own template.

  • User profile image

    @MasterPi: I'll look into your suggestion.

    At as minimum, is there ANY way to bind from within a CellTemplate so that when the converter is invoked that it can tell from which column it is? I tried many bindings and can't figure out how to pass in the column name/index into the converter.

    I tried the below suggested binding from here but that didn't work.

    <Binding Path="Column.Index"/>

  • User profile image

    @BitFlipper: It doesn't look like GridViewColumn has an Index property. I think only the Grid knows about it.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.