c# - Set value to one property thru a range of fixed buttons or a custom value -


i have 1 property in model stores time in seconds. on ui, have display options thru radio buttons 1,5,10,15,30 min , 1 hr options along custom value radio button minute , hour option in combobox.

on selecting custom value, value in text box , combo box minuter , hour options set interval in model. rest using converter , parameter set value. follows:

 public class samplingintervalconverter : ivalueconverter     {         static  int[] secondsarray = new int[]{60,300,600,900,1800,3600};         object ivalueconverter.convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)         {             int dataseconds = 0;             int parameterseconds = 0;             if (int.tryparse(value.tostring(), out dataseconds))             {                 if(int.tryparse(parameter.tostring(),out parameterseconds))                 {                     if (dataseconds == parameterseconds)                     {                         return true;                     }                 }                 else if (parameter.tostring().equals("custom") && !secondsarray.contains(dataseconds))                 {                     return true;                 }             }              return false;         }          object ivalueconverter.convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture)         {             if ((bool)value)             {                 int parameterseconds = 0;                 if (int.tryparse(parameter.tostring(), out parameterseconds))                 {                     return parameterseconds;                 }             }             return 0;         }     } 

is there better way of solving problem. appreciate on this.

thanks :)

if have use of these buttons, either connect click handlers or bind command objects them, depending on whether use view models or not. in code behind or view model, react button clicks adding seconds value property.

personally, display timespan object instead of seconds integer because can use nice stringformat {0:hh:mm} display duration in user friendly way. this:

public timespan duration {     { return timespan.fromseconds(lengthinseconds); }     set     {         if (timespan.fromseconds(lengthinseconds) != value)         {             lengthinseconds = (short)value.totalseconds;             notifypropertychanged("duration");         }     } } 

alternatively, take @ what best, free time picker wpf? post controls users can use select timespan values.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -