Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have ListBox with 7 items of Rainbow colors and stackpanel with respective colors. I need to bind this stack panel visibility based on ListBox selected Item. In simple words if i select Red Color from ListBox then Red Color stackpanel should be visible and rest other stack panels should collapse

What I have tried:

Visibility="{Binding Path=SelectedItem,Mode=OneWay,ElementName=ListBox1}"
Posted
Updated 28-Sep-16 4:12am

1 solution

Binding should work like this, just that the selecteditem won't be of the correct type for System.Windows.Visibility - so use a converter, or make it a (calculated) property on your ViewModel (but it seems you don't use MVVM - you know that WPF works best with MVVM?). Maybe a DataTrigger could do the same without a converter (not 100% shure, din't try it for your case)
 
Share this answer
 
Comments
Member 11559270 29-Sep-16 0:49am    
yeah i used converter but when i click the any listbox item all the stack panels are showing but i need respective stack panel

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900