c# - Modify data template properties of listbox in code behind -
i have listbox in xaml per code shown below.
<listbox name="mylistbox"> <listbox.itemtemplate> <datatemplate> <image source="{binding path=image}" width="175" height="175" verticalalignment="center" horizontalalignment="center"/> </datatemplate> </listbox.itemtemplate> </listbox>
at runtime based on condition, want change height
, width
properties value using code behind. please can guide me in achieving desired functionality.
many thanks
i think easiest way achieve bind width , height of image 2 properties. if want change width , height of images can use 2 properties in code behind , if want able individually same bind against properties in collection items.
<listbox name="mylistbox"> <listbox.itemtemplate> <datatemplate> <image source="{binding path=image}" width="{binding elementname=mywindow, path=listboxtemplatewidth}" height="{binding elementname=mywindow, path=listboxtemplateheight}" verticalalignment="center" horizontalalignment="center"/> </datatemplate> </listbox.itemtemplate> </listbox>
and in code behind define 2 properties
private double m_listboxtemplateheight; public double listboxtemplateheight { { return m_listboxtemplateheight; } private set { m_listboxtemplateheight = value; onpropertychanged("listboxtemplateheight"); } } private double m_listboxtemplatewidth; public double listboxtemplatewidth { { return m_listboxtemplatewidth; } private set { m_listboxtemplatewidth = value; onpropertychanged("listboxtemplatewidth"); } } if (somecondition == true) { listboxtemplateheight = 200; listboxtemplatewidth = 200; }
this way, listboxitems increase/decrease in size width/height of images.
Comments
Post a Comment