Binded ObjectDataProvider

How to bind to an instance method of item in ItemsControl?

Like

<ListBox>

<ListBox.ItemTemplate>

<DataTemplate DataType="c:MyCollectionItem">

<DataTemplate.Resources>

<ObjectDataProvider x:Key="myItems"

ObjectInstance="{Binding .}"

MethodName="GetItems" />

</DataTemplate.Resources>

<ComboBox ItemsSource="{Binding Source={StaticResource myItems}}" />

</DataTemplate>

</ListBox.ItemTemplate>

<c:MyCollectionItem />

<c:MyCollectionItem />

<c:MyCollectionItem />

</ListBox>

Unfortunately, binding is not allowed on ObjectInstance property of ObjectDataProvider..

Thanks for any hints, Jan

[3511 byte] By [JanKu?era] at [2008-1-8]
# 1

I'm not sure if you describe the same scenario but take a look at my post.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1958513&SiteID=1

Hope it helps

Alex

alex_ger at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2

Hello Alex, thank you for the hint!

In my case, the IValueConverter could do the workaround as good as in your scenario, by returning a collection.

I just wonder if there is any scenario like this for which the value converter would be no match...

Actually, I've solved this by backing the method with a property, and then the binding is really easy. :-).

JanKu?era at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified