c# - WPF ProgressBar controltemplate how to bind Template Background -
simply set have progress bar acts battery indicator.
i want minor template override.
the background of battery should alter based on range of battery levels.
the actual progress bar bound integer value in viewmodel called batterylevel.
this passed converter homecoming background.
the problem is...the binding in controltemplate isn't changing background color of border.
it stays blank (maybe null...not sure).
my question: necessary able accomplish binding part_indicator progressbar's background
here code override template.
<progressbar name="_batterystat" background="{binding batterylevel, converter={staticresource batteryleveltocolorconverter}}"> <progressbar.template> <controltemplate targettype="{x:type progressbar}"> <grid> <border x:name="part_track" background="white" borderbrush="{x:null}" /> <border horizontalalignment="left" x:name="part_indicator" background="{binding relativesource={relativesource templatedparent}, path=background}" borderbrush="{x:null}" /> </grid> </controltemplate> </progressbar.template> </progressbar>
and converter:
public class batteryleveltocolorconverter : ivalueconverter { public object convert(object value, type targettype, object parameter, cultureinfo culture) { var battlevel = system.convert.toint32(value); if (battlevel <= globalsservice.batterlevelcriticalsetting) homecoming new solidcolorbrush(colors.red); if (battlevel <= globalsservice.batterlevellowsetting) homecoming new solidcolorbrush(colors.yellow); homecoming new solidcolorbrush(colors.blue); } public object convertback(object value, type targettype, object parameter, cultureinfo culture) { throw new notimplementedexception(); } }
c# wpf binding controltemplate valueconverter
No comments:
Post a Comment