wpf - Converting Data Trigger XAML to C# -
<image width="16"> <image.style> <style targettype="{x:type image}"> <style.triggers> <datatrigger binding="{binding value}" value="false"> <setter property="source" value="resources/image1.png"/> </datatrigger> <datatrigger binding="{binding value}" value="true"> <setter property="source" value="resources/image2.png"/> </datatrigger> </style.triggers> </style> </image.style> </image>
referring xaml code above, i'm confused in how convert xaml, example data trigger part, has idea?
thanks.
after little refactor, think u need this:
style style = new style(typeof(image)); // style setter handle 'false' case style.setters.add(new setter(image.sourceproperty, new bitmapimage(new uri("resources/image2.png", urikind.relative)))); // datatrigger handle 'true' case datatrigger datatrigger = new datatrigger(); datatrigger.binding = new binding("value"); datatrigger.value = true; datatrigger.setters.add(new setter(image.sourceproperty, new bitmapimage(new uri("resources/image1.png", urikind.relative)))); style.triggers.add(datatrigger); this.image.style = style;
Comments
Post a Comment