xaml - Disable certain ListBox items -
what best way disable items of listbox..? have following code in xaml
<listbox x:name="scenariolist" grid.row="1" selectionchanged="scenariocontrol_selectionchanged" selectionmode="single" horizontalalignment="left" style="{staticresource scenariolistboxstyle}" itemcontainerstyle="{staticresource listboxitemstyle}" verticalalignment="top" margin="0"> <listbox.itemtemplate> <datatemplate> <stackpanel orientation="horizontal"> <textblock text="{binding converter={staticresource scenariobinder}}" style="{staticresource listitemtextstyle}"/> </stackpanel> </datatemplate> </listbox.itemtemplate> </listbox> i binding data in code behind , using following ivalueconverter bind data textbox
public class scenariobindingconverter : ivalueconverter { public object convert(object value, type targettype, object parameter, string language) { var keyvalpair = value keyvaluepair<feature, bool>?; return !keyvalpair.hasvalue ? dependencyproperty.unsetvalue : keyvalpair.value.key.displayname(); } public object convertback(object value, type targettype, object parameter, string language) { return true; } } the feature object has isenabled property bind directly listbox items , if item disabled, list box item needs grayed out.
could please point me in right direction?
as per code, if you're using <stackpanel> or <textblock> in data template you'll not isenabled property of these 2 elements bind with. instead can use ishittestvisible property enable or disable tapping event on elements.
but setting ishittestvisible element not turn gray so, you'll have bind foreground color assigning solidcolorbrush value textblock well.
<listbox.itemtemplate> <datatemplate> <stackpanel ... ishittestvisible="{binding converter={staticresource hittestvisibleconverter}"> <textblock ... /> </stackpanel> </datatemplate> </listbox.itemtemplate> with that, use converter bind isenabled property value have, ishittestvisible property.
hope helps..! ask if further requires..
Comments
Post a Comment