wpf - Change border color depending on boolean value -
i have border wihch want alter color depending on boolean variable. used link here implement boolean
color
converter.
the code looks this:
the xaml:
<border width="45" height="45" cornerradius="5" background="{binding path=livenessactive, converter={staticresource brushcolorconverter}}" />
the livenessactive variable in background:
public bool livenessactive { { homecoming _livenessactive; } set { _livenessactive = value; onpropertychanged("livenessactive"); } }
where class has inheritance inotifypropertychanged
, has implemented onpropertychanged
event.
the brushcolorconverter.cs:
public class brushcolorconverter : ivalueconverter { public object convert(object value, type targettype, object parameter, cultureinfo culture) { if ((bool)value) { { homecoming new solidcolorbrush(colors.greenyellow); } } homecoming new solidcolorbrush(colors.darkgray); } public object convertback(object value, type targettype, object parameter, cultureinfo culture) { throw new notimplementedexception(); } }
but can't fire brushcolorconverter
. i'm doing wrong?
2nd: if want utilize window?
<border width="45" height="45" cornerradius="5" background="{binding path=livenessactive, converter={staticresource brushcolorconverter}, relativesource={relativesource mode=findancestor, ancestortype={x:type view:mywindowname}}}" />
i used same code , it's not finding it.
to sum comments since there seems nil wrong code above suggest there problem binding context
background="{binding path=livenessactive, converter={staticresource brushcolorconverter}}"
you cannot reference 1 window
window
. if have 2 independent window
s each border
should trigger on same property alter set datacontext
of both windows same instance of view model.
wpf xaml converter
No comments:
Post a Comment