file360

Log | Files | Refs

BoolToVisibilityConverter.cs (1003B)


      1 namespace File360
      2 {
      3     using System;
      4     using Windows.UI.Xaml;
      5     using Windows.UI.Xaml.Data;
      6 
      7     /// <summary>
      8     /// Converts a Boolean into a Visibility.
      9     /// </summary>
     10     public class BoolToVisibilityConverter : IValueConverter
     11     {
     12         /// <summary>
     13         /// If set to True, conversion is reversed: True will become Collapsed.
     14         /// </summary>
     15         public bool IsReversed { get; set; }
     16 
     17         public object Convert(object value, Type targetType, object parameter, string language)
     18         {
     19             var val = System.Convert.ToBoolean(value);
     20             if (this.IsReversed)
     21             {
     22                 val = !val;
     23             }
     24 
     25             if (val)
     26             {
     27                 return Visibility.Visible;
     28             }
     29 
     30             return Visibility.Collapsed;
     31         }
     32 
     33         public object ConvertBack(object value, Type targetType, object parameter, string language)
     34         {
     35             throw new NotImplementedException();
     36         }
     37         
     38     }
     39 }