c# - Set IsEnabled Property of ComboBox Based on SelectedItem -
i want enable/disable combobox based on if there item selected in combobox. able working setting trigger on style, overrides custom global style combobox. there way same functionality without losing style?
<combobox grid.column="1" grid.row="1" name="analysiscombobox" minwidth="200" verticalalignment="center" horizontalalignment="left" itemssource="{binding path=availableanalysis}"> <combobox.style> <style targettype="{x:type combobox}"> <setter property="isenabled" value="true" /> <style.triggers> <datatrigger binding="{binding selecteditem,elementname=applicationcombobox}" value="{x:null}"> <setter property="isenabled" value="false" /> </datatrigger> </style.triggers> </style> </combobox.style> </combobox>
you don't need via style, can bind isenabled property directly using value converter follows:
<combobox grid.column="1" grid.row="1" name="analysiscombobox" minwidth="200" verticalalignment="center" horizontalalignment="left" isenabled={binding selecteditem, elementname=applicationcombobox, converter={staticresource nulltofalseconverter}}" itemssource="{binding path=availableanalysis}"/>
where nulltofalseconverter key instance of followsing converter:
public class nulltofalseconverter: ivalueconverter { public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { return value == null; } public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { throw new notimplementedexception(); } }
Comments
Post a Comment