xaml - Binding issue linked to DispatcherTimer -


i'm building universal windows application allow users track time spent on specific task.

on mainpage i'm binding observablecollection, containing time registrations. when task running want update time spent every second.

i'm using dispatchertimer (whichs runs fine) update time spent active timers. have implemented inotifypropertychanged , i'm firing propertychanged event in setter of property binded xaml.

the problem

i'm expecting ui update every second updates once - each run - , @ irregular timestamps. think i'm doing wrong binding.

your appreciated!

mainpage_loaded

    private async void mainpage_loaded(object sender, routedeventargs e)     {         timerrepository repository = new timerrepository();         this.timers = await repository.gettimersasync();          _timer = new dispatchertimer();         _timer.interval = timespan.fromseconds(1);         _timer.tick += _timer_tick;         _timer.start();     } 

dispatcher timer, 1 second tick handling:

    private void _timer_tick(object sender, object e)     {         if (this.timers != null)         {             foreach (var timer in this.timers.where(m => m.isrunning))             {                 timer.tick();             }         }     } 

custom timer model

public class sprinttimer : inotifypropertychanged {     private string _name;     private datetime? _timerstarted;      public event propertychangedeventhandler propertychanged;      private timespan _registedtime;     public timespan registeredtime     {                 {             return _registedtime;         }         set         {             _registedtime = value;             propertychanged?.invoke(this, new propertychangedeventargs("registeredtime"));         }     }      public bool isrunning     {                 {             return this._timerstarted.hasvalue;         }     }      public void start()     {         if (!this._timerstarted.hasvalue)         {             _timerstarted = datetime.now;         }     }      public void tick()     {         if (this.isrunning)         {             this.registeredtime = datetime.now - _timerstarted.value;         }     } } 

xaml

<scrollviewer bringintoviewonfocuschange="false" verticalscrollbarvisibility="hidden">         <stackpanel x:name="stackpanel" grid.row="0" margin="20 20 20 0">             <itemscontrol itemssource="{x:bind timers, mode=oneway}">                 <itemscontrol.itemtemplate>                     <datatemplate x:datatype="data:sprinttimer">                         <grid borderthickness="1">                             <grid.columndefinitions>                                 <columndefinition width="*"></columndefinition>                                 <columndefinition width="*"></columndefinition>                                 <columndefinition width="auto"></columndefinition>                             </grid.columndefinitions>                             <textblock text="{x:bind name}" grid.column="0" fontsize="18" verticalalignment="center"></textblock>                             <textblock text="{x:bind registeredtime}" grid.column="1" verticalalignment="center" textalignment="right" fontsize="22" margin="10"></textblock>                             <button grid.column="2" verticalalignment="center" margin="10" name="btnstarttimer" click="btnstarttimer_click">                                 <symbolicon x:name="icon" symbol="play"></symbolicon>                             </button>                         </grid>                     </datatemplate>                 </itemscontrol.itemtemplate>             </itemscontrol>         </stackpanel>     </scrollviewer> 

ui

enter image description here

the default mode of x:bind onetime, need add mode=oneway binding expressions.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -