开发者

Bind to a method in code behind

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开发者_StackOverflow that I want to bind the text in the TextBlock to a different ItemsSource 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜