0

I have a Listbox with items created through databinding. The item template creates a custom view for each generated item. Each generated item view is its own user control.

I'd like to change the state of the listbox to something like "Details" vs. "Compact" and have each item have its own state changed automatically. The view item knows what to show or hide based on its state. I can't seem to change the state of that generated user control from a higher level (the button for changing view modes).

I hope this is clear enough. I'll add details if it helps.

Thank you very much for any help!

Arian Kulp
  • 831
  • 8
  • 31
  • Thanks for the quick responses! Sorry, I should have been more clear. I specifically need to do a change state on the generated user control, not just set a property value. I want to declare an Event Trigger so the source is a button being clicked, then a ChangeStateAction (I'd like everything declarative) on the user control. The button is at the level of the ListBox, so a simple ancestor bind wouldn't find it. In reality, it's not making the user control's property match another control's property value -- it's triggering a state change based on a click event of a button somewhere else. – Arian Kulp Jul 12 '10 at 22:28

2 Answers2

1

Set a data trigger in your generated control which is bound to the relative property of a parent. More info here on uses of RelativeSource - your looking for the ancestor option, which will be the parent listbox you mention.

Lets say you expose a ViewType property on the listbox, then something like

{Binding Path=ViewType, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}

should work.

Community
  • 1
  • 1
cristobalito
  • 4,192
  • 1
  • 29
  • 41
0

You can set

MyValue = "{Binding Path=SelectedItem.CustomProperty, Converter=CustomPropertyConverter}"

This will walk down the object chain down your selected item.

FindAncestor climbs up the chain.

Nate Noonen
  • 1,371
  • 9
  • 19