xaml - WPF - Binding a ComboBoxItem visibility using BooleanToVisibilityConverter -
i have datagrid, column has combobox in header. want control visibility of items in combobox based on value of flag.
this how xaml looks:
<datagrid x:name="table1" height="{binding elementname=elasticone1,path=actualheight}" width="{binding elementname=elasticone1,path=actualwidth}" padding="5,5,5,5" isreadonly="true" horizontalalignment="stretch" verticalalignment="stretch" selectionmode="single" > <datagrid.columns> <datagridtextcolumn x:name="column2" header="source" width="80"> <datagridtextcolumn.headertemplate> <datatemplate> <stackpanel margin="0"> <stackpanel.resources> <booleantovisibilityconverter x:key="booltovis"/> </stackpanel.resources> <textblock text="{binding content, relativesource={relativesource mode=templatedparent}}" margin="5"/> <combobox horizontalalignment="stretch" margin="0" > <comboboxitem tag="0" isselected="true">all</comboboxitem> <comboboxitem visibility="{binding showcopybookinsourcecombobox, converter={staticresource booltovis}}">copybook</comboboxitem> <comboboxitem>prototype</comboboxitem> </combobox> </stackpanel> </datatemplate> </datagridtextcolumn.headertemplate> </datagridtextcolumn> </datagrid.columns>
and declaration of flag in code:
public readonly property showcopybookinsourcecombobox boolean return myflag1 or myflag2 end end property
no matter value of flag, combobox item showing. haven't seen examples far of binding visibility of comboboxitem way. on wrong path?
thanks input.
edit: booleantovisibilityconverter built-in class using - https://msdn.microsoft.com/en-us/library/system.windows.controls.booleantovisibilityconverter(v=vs.110).aspx
Comments
Post a Comment