c# - MVVM, when to use IValueConverter and when "formatted" property -


im designing app models , started wondering, there general thumb rule when should use formatted properties , when ivalueconverters?

for example have model this:

public interface iflight {   datetime arrivaltime { get; }   timespan duration { get; }   int lengthmeters{ get; } } 

i have list of flight items, can use ivalueconverters display arrivaltime formatted time, duration formatted hours, length formatted miles.

another way is:

 public interface iflight {     datetime arrivaltime { get; }     string arrivaltimeformatted { get; }      timespan duration { get; }     string durationformatted { get; }      int lengthmeters{ get; }     string lengthformatetd{ get; } } 

now can bind arrivaltimeformatted, durationformatted , lengthformatetd view. makes view (xaml) cleaner models little more complicated.

so 1 better approach? not general question.

i think comes down personal reference.

usually, use formatters types such string , datetim want them printed on ui in pretty way.

with valueconverters take totally different approach. common valuecnverter see if booleantovisibillityconverter have bool decides whether control displayed or not. when want have property decides whether actions execute or not cannot use property in straight forward way binding.

i hope made sense :)


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -