User Tools

Site Tools


notes:uwp:converters

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
notes:uwp:converters [2017/03/10]
admin [Examples]
notes:uwp:converters [2017/03/10] (current)
admin [Examples]
Line 89: Line 89:
         double hours = span.TotalHours;​         double hours = span.TotalHours;​
         return hours;         return hours;
 +    }
 +}
 +</​code>​
 +
 +
 +Example: NumberToBooleanConverter
 +
 +<code csharp>
 +class NumberToBooleanConverter : IValueConverter
 +{
 +    // Returns True is the provided number is greater than 0.
 +    // The value parameter may be double, float, int, or decimal.
 +    public object Convert(object value, Type targetType, object parameter, string language)
 +    {
 +        if (value == null)
 +            return false;
 +        string str = value.ToString();​
 +
 +        double n;
 +        if (!(Double.TryParse(str,​ out n)))
 +            return false;
 +
 +        return (n > 0.000001);
 +    }
 +
 +    public object ConvertBack(object value, Type targetType, object parameter, string language)
 +    {
 +        throw new NotImplementedException();​
     }     }
 } }
 </​code>​ </​code>​
  
notes/uwp/converters.txt ยท Last modified: 2017/03/10 by admin