c# - Cannot Make Binding to ZIndex from Another Element in WPF -
i want make binding zindex of element in wpf in same .xaml
file not work.
the element bound.
<border x:name="bubbletop" cornerradius="5" background="#ebf5eb" padding="8,6" borderbrush="lightgray" borderthickness="1" grid.zindex="3"> <contentpresenter /> </border>
the element initial binding.
<textblock x:name="statustext" margin="..." foreground="{binding elementname=bubbletop, path=grid.zindex, converter={staticresource togglecolorconverter}}" fontweight="bold" text="..."/>
in converter, set change foreground color according zindex of border element.
public object convert(object value, type targettype, object parameter, cultureinfo culture) { int z = (int)value; if (z == 3) return "red"; else return "blue"; }
but not work. hint?
the converter have work fine, except path
binding wrong. when binding attached property, have put path in parens path parsed correctly.
that said, don't think converter makes sense here. can use styling address simple toggle this. allows keep more of view logic in xaml.
for example:
<textblock x:name="statustext" margin="..." fontweight="bold" text="..."> <textblock.style> <p:style targettype="textblock"> <setter property="foreground" value="blue"/> <p:style.triggers> <datatrigger binding="{binding elementname=bubbletop, path=(grid.zindex)}" value="3"> <setter property="foreground" value="red"/> </datatrigger> </p:style.triggers> </p:style> </textblock.style> </textblock>
(note: can omit p:
xml namespace <style/>
element. include because stack overflow code formatter gets confused when there's plain <style/>
element in xml , won't format xml correctly.)
Comments
Post a Comment