Mercurial > silverbladetech
view MetroWpf/MetroWpf.Xaml/Converters/BooleanToVisibilityConverter.cs @ 18:8049f7c58c2b
Login form 75% there
author | stevenh7776 stevenhollidge@hotmail.com |
---|---|
date | Wed, 14 Mar 2012 18:06:36 +0700 |
parents | |
children |
line wrap: on
line source
// http://drwpf.com/blog/2009/03/17/tips-and-tricks-making-value-converters-more-accessible-in-markup/ // to use in xaml: <TextBlock Text="{Binding SomePath, Converter={src:BoolVisibilityConverter}}" /> using System; using System.Windows; using System.Windows.Data; using System.Windows.Markup; using System.Globalization; namespace MetroWpf.Xaml.Converters { public class BooleanToVisibilityConverter : MarkupExtension, IValueConverter { private static BooleanToVisibilityConverter booleanToVisibilityConverter = null; public override object ProvideValue(IServiceProvider serviceProvider) { if (null == booleanToVisibilityConverter) booleanToVisibilityConverter = new BooleanToVisibilityConverter(); return booleanToVisibilityConverter; } public bool IsReversed { get; set; } public bool UseHidden { get; set; } #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var val = System.Convert.ToBoolean(value, CultureInfo.InvariantCulture); if (this.IsReversed) { val = !val; } if (val) { return Visibility.Visible; } return this.UseHidden ? Visibility.Hidden : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } #endregion } }