Yossi Dahan
Yossi Dahan

Reputation: 5357

Binding a custom control in a pivot item to the current item in the pivot control's ItemsSource

I have a pivot control which is bound to a list through the ItemsSource attribute.

In the ItemTemplate I would like to place a custom control, in which I would like to bind controls to the current item in the pivot's list.

I'm looking for something around

<MyControl Item="{Binding <Something here>}" />

But am not sure what <something here> should be to point to the current item in the control's databound list?

Thanks

Upvotes: 1

Views: 555

Answers (2)

Stuart
Stuart

Reputation: 66882

Maybe I'm misunderstanding, but if this control is going inside the PivotItem then isn't the path you are looking for just:

<MyControl Item="{Binding}" />

e.g. if using a TextBlock then you might use:

<TextBlock Text="{Binding}" />
  • and this would then use the ToString() of the current pivot item

Or if using a complicated user control you might use:

<MySpecialControl DataContext="{Binding}" />

Sorry if I've got this wrong!

Upvotes: 0

Derek Lakin
Derek Lakin

Reputation: 16319

You could do one of two things (that immediately spring to mind):

  1. Include the information you need in the object that your list item binds to. This is likely to be repetitive and probably difficult to manage, but I don't know the details of your data, so it's hard to say.
  2. Use a proxy for the Pivot.SelectedItem property, which you add as a resource to the page and bind to the pivot's SelectedItem property. You can then reference that resource as you would any other resource to get at the selected item.

If you're not familiar with this proxy concept, then Dan Wahlin's post on the subject should help.

Upvotes: 1

Related Questions