c# - WPF code to turn visibility off:on of multiple stackpanels -



c# - WPF code to turn visibility off:on of multiple stackpanels -

i have multiple stackpanels collapsed @ first , button clicked stackpanel relating button click becomes visible. off right have works.

private void button1_click(object sender, routedeventargs e) { dgrid.itemssource = filldatagrid("shipworksconnection", "getpicklistitems", "picklist"); sp1.visibility = visibility.visible; sp2.visibility = visibility.collapsed; sp3.visibility = visibility.collapsed; sp4.visibility = visibility.collapsed; } private void button2_click(object sender, routedeventargs e) { dgrid.itemssource = filldatagrid("supplyconnection", "getallsupplies", "supplies"); sp1.visibility = visibility.collapsed; sp2.visibility = visibility.visible; sp3.visibility = visibility.collapsed; sp4.visibility = visibility.collapsed; }

and on multiple button click events. way handle , since i'll adding more button click events there else create code more reusable.

if there combined logic in hiding / showing of elements, can utilize binding toggle visibility.

for sample, have create viewmodel , create property theconditionproperty in it. bind view model control. in scenario, can bind array of items, create easier adding properties on , on again.

<stackpanel> <stackpanel.style> <style targettype="stackpanel"> <style.triggers> <datatrigger binding="{binding theconditionproperty}" value="false"> <setter property="visibility" value="collapsed" /> </datatrigger> </style.triggers> </style> </stackpanel.style> </stackpanel>

c# wpf

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -