开发者

Binding visibility of control inside listbox to a property not contained in the itemsource collection

开发者 https://www.devze.com 2023-01-13 01:37 出处:网络
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 inst开发者_开

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 inst开发者_开发百科ance 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?


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.

0

精彩评论

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