c# - How to use DynamicResource of Label content? -
i try development wpf application "dynamicresource", have label in xaml file this:
<window.resources> <local:bindingclass x:key="mydatasource"/> <local:utilitygioco x:key="myutilitygame" /> </window.resources> <label x:name="labeltempo" datacontext="{dynamicresource myutilitygame}" content="{binding path=tempoesecuzioneesercizio}" fontfamily="arial" fontsize="21" foreground="gray" grid.column="0" grid.row="1" fontweight="bold" margin="15,40,0,0"/> in utilitygioco class have code:
public string tempoesecuzioneesercizio { set; get; } private void displaytimer(object sender, eventargs e) { try { // code goes here //console.writeline(datetime.now.hour.tostring() + ":"); if (timesecond == 59) { timesecond = 0; timeminutes++; } //se il contatore dei minuti รจ maggiore di 0, devo mostrare una scritta altrimenti un altra if (timeminutes > 0) { tempoesecuzioneesercizio = timeminutes + " min " + ++timesecond + " sec"; } else { tempoesecuzioneesercizio = ++timesecond + " sec"; } } catch (exception ex) { log.error("mainwindow metodo: displaytimer ", ex); } } the "displaytimer" method called every time, content of label blank.
can me?
in utilitygioco class implement inotifypropertychanged interface , notify change in setter of tempoesecuzioneesercizio property.
example:
private string _tempoesecuzioneesercizio; public string tempoesecuzioneesercizio { set { _tempoesecuzioneesercizio = value; if (propertychanged != null) { propertychanged(this, new propertychangedeventargs("tempoesecuzioneesercizio")); } } { return _tempoesecuzioneesercizio; } }
Comments
Post a Comment