c# - How do I create a ProgressBar which is hidden when the Value is 0? -
the following doesn't quite work (progressvalue value set in datacontext.)
<statusbaritem grid.column="1"> <statusbaritem.resources> <style targettype="progressbar"> <style.triggers> <datatrigger binding="{binding progressvalue}" value="0"> <setter property="visibility" value="hidden"/> </datatrigger> </style.triggers> </style> </statusbaritem.resources> <progressbar value="{binding progressvalue}" grid.column="1" width="80" height="13"> </progressbar> </statusbaritem>
try specifying minimum (and maximum) value. after setting seems work version of code.
with xaml:
<statusbaritem x:name="feedback" grid.row="1"> <statusbaritem.resources> <style targettype="progressbar"> <style.triggers> <datatrigger binding="{binding}" value="0"> <setter property="visibility" value="hidden"/> </datatrigger> </style.triggers> </style> </statusbaritem.resources> <progressbar value="{binding mode=oneway}" minimum="0" maximum="10" grid.column="1" width="80" height="13"> </progressbar> </statusbaritem>
and code in constructor of mainwindows.xaml.cs (for testing purposes only)
int value = 10; public mainwindow() { initializecomponent(); feedback.datacontext = value; timer t = new timer(500); t.elapsed += (s, e) => { if (value > 0) dispatcher.invoke(new action(() => { feedback.datacontext = --value; })); else t.stop(); }; t.start(); }
i progress bar go 10 down 0 @ point progress bar disappears.
Comments
Post a Comment