c# - Programmatically add MultiTrigger to ContentControl sub-class -


everything works fine until call this.triggers.add(triggerfocus). class sub-classes contentcontrol.

here's code:

private void createtriggers()     {         triggerfocus = new multitrigger         {             conditions =              {                 new condition                 {                     property = isfocusedproperty,                     value = true                 },                 new condition                 {                                                                         property = iskeyboardfocusedproperty,                     value = true                 }             },             setters =             {                 new setter                 {                     property = setfocusproperty,                     value = true                 },             }         };          this.triggers.add(triggerfocus);     } 

any ideas?

here's equivalent xaml throws error:

<contentcontrol.triggers>             <multitrigger>                 <multitrigger.conditions>                     <condition property="contentcontrol.isfocused" value="true"/>                     <condition property="contentcontrol.iskeyboardfocused" value="true"/>                 </multitrigger.conditions>                 <setter targetname="borderfocus" property="contentcontrol.visibility" value="visible" />             </multitrigger>         </contentcontrol.triggers> 

after testing have isolated problem multitrigger above. seems work fine if put trigger in template or style.

the error thrown not informative: initialization of 'system.windows.controls.contentcontrol' threw exception

you can put eventtriggers <contentcontrol.triggers> collection.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -