c# - How to reuse style with two different bindings? -
i have style:
<style x:key="blinkstyle"> <style.triggers> <datatrigger binding="{binding path=blinkforerror, relativesource={relativesource findancestor, ancestortype={x:type loc:devicesrepositoryeditorusercontrol}}}" value="true"> <datatrigger.enteractions> <beginstoryboard name="blinkbeginstoryboard"> <storyboard> <coloranimation to="red" storyboard.targetproperty="(background).(solidcolorbrush.color)" fillbehavior="stop" duration="0:0:0.4" repeatbehavior="forever" autoreverse="true" /> </storyboard> </beginstoryboard> </datatrigger.enteractions> <datatrigger.exitactions> <stopstoryboard beginstoryboardname="blinkbeginstoryboard" /> </datatrigger.exitactions> </datatrigger> </style.triggers> </style> whenever bound dependency-property blinkforerror set true, start blinking. works great, this:
<!-- when blinkforerror set true, textbox, named "one", blinks: --> <textbox name="one" style="{staticresource resourcekey=blinkstyle}"/> thing want same thing, bound dependency-property, anotherblinkforerror:
<!-- when anotherblinkforerror set true, textbox, named "two", blinks: --> <textbox name="two" style="{staticresource resourcekey=anotherblinkstyle}"/> i can duplicate whole style , alter datatrigger's binding part.
is there way avoid duplication, reuse same style twice 2 different bindings?
you seek , create utilize of tag properties on textboxes , bind them blinkforerror , blinkforanothererror. in style definition binding check tag value (you'd have utilize relativesource , findancestor options) instead of blink properties.
but honest, if there 2 textboxes , respective error properties go 2 separate styles it's less hassle.
c# wpf xaml binding wpf-style
No comments:
Post a Comment