views:

29

answers:

1

I have a listbox with a datatemplate that holds a number of controls bound to my collection.

I want to bind the visibility of one of the controls to a property defined in the class , an instance of which is set to datacontext in code behind.This property is not a member of collection which is item source of the listbox.

How can this be done?

A: 

There are a few methods to do this.

  • Set Binding.Source to the data context you want. You could add the DataContext to the resources and use {Binding Source={StaticResource ?}}

  • Give the element that has the data context you need a name and use {Binding DataContext.Property, ElementName=?}. This might not be applicable if your ItemTemplate is in a resource.

  • Add the property you want to the items in the collection either directly or create a wrapper class.

Kris