tags:

views:

71

answers:

1

I have a custom control template for a listview that puts an extra line in for each record, thats defined something like this in Window.Resources...

<ControlTemplate TargetType="ListBoxItem">
    <Border>
        <StackPanel>
            <GridViewRowPresenter>
            <TextBlock Name="myTextBlock" />
        </StackPanel>
     </Border>
     <ControlTemplate.Triggers>
         //Triggers here
     </ControlTemplate.Triggers>
</ControlTemplate>

My problem is that I want to bind the text in the TextBlock to a different itemsource than the one that will be bound to the actual Listbox when its instantiated. Binding programatically is impossible. I've tried substituting the Textblock for another listview and binding to a method, but I couldn't work out how to use ObjectDataProvider and bind to a method in my code behind (which contains a method that would return a list of things I want to bind too), but ran into problems with this as well.

A quick step by step in case I'm not being clear:

-I have a Listview template that adds an extra row for each record

-This listview will be bound to (say) a collection of Foo objects.

-Problem is I then want to bind the extra row to a completely different itemsource than the main listview. It doesnt seem like I can do this from within my template :/

So - is there a way to straight up bind to the results of a method defined in my code behind, which I could reference in the template.

+1  A: 

Ok, that is the idea:

1) create list box which is bound to Foo with such item template:

-------------
| DATA HERE |
|           |
-------------

2) create list box which is bound to completely different itemsource with such item template:

-------------
|           |
| DATA HERE |
-------------

3) draw the first list box behind the second one.

If there are the same count of items (this is your case as I understand), you will achieve the visual effect you want. Hope it helps.

EDIT
This method does not correspond your present template, but it is a variant of solution.

levanovd
If you are going this route, you'll also need to worry about styling the listboxes so that the overlay is not apparent, as well as synchronize the selections so that selecting an item in the first list box clears the selection in the second. And you'll need some fancy logic if you want keyboard accessibility...
Nicholas Armstrong
yes, sure, Nicholas Armstrong is right, but it is not as complicated as seems at first look.
levanovd
Keyboard functionality isn't an issue at all, but I see how that'd be difficult. Never occurred to me that I should start editing my initial design to make the thing easier.
MoominTroll