c# - Pass value of a StaticResource to ConverterParameter in a combine string -
i wrote converter
value
bool
parameter
string
i use this:
borderbrush="{binding isselected, converter={staticresource booltocolorbrushconverter}, converterparameter='#ff00bfff;#0000bfff'}"
if value
true
converter return colorbrush
first color hex code in parameter else return colorbrush
second color hex code.
my converter work but want know how can use this:
<color x:key="mycolor1">#66bb66</color> -------------------- borderbrush="{binding isselected, converter={staticresource booltocolorbrushconverter}, converterparameter=#ff00bfff;{staticresource mycolor1}}"
result in design mode:
result @ runtime:
but need color hex code of staticresource
in parameter this:
parameter: "#ff00bfff;#66bb66"
my question how can pass staticresource
value in combine string converterparameter
???
what solution?
i know it's bit late, can late visitors:
here converter code:
public class booltoborderbrushconverter : ivalueconverter { public solidcolorbrush truecolor { get; set; } public solidcolorbrush falsecolor { get; set; } // example compares binding property (string) 1 parameter (also in string) public object convert(object value, type targettype, object parameter, cultureinfo culture) { if (value != null && parameter != null) { if (string.compare(value.tostring(), parameter.tostring(), true) == 0) { return this.truecolor; } else { return this.falsecolor; } } return this.falsecolor; } public object convertback(object value, type targettype, object parameter, cultureinfo culture) { throw new notimplementedexception(); } }
then can configure converter in xaml (in resourcedictionary section):
<resourcedictionary> <local:booltoborderbrushconverter x:key="brushconverter" truecolor="{staticresource mytruecolor}" falsecolor="transparent"> </resourcedictionary>
and how use converter:
<border borderbrush="{binding myproperty, converter={staticresource brushconverter}, converterparameter=abc}"/>
Comments
Post a Comment