Facebook Twitter Gplus LinkedIn YouTube Google Maps RSS
Home Technical IValueConverter: Bool to IsChecked (Radio Button)
formats

IValueConverter: Bool to IsChecked (Radio Button)

Published on June 30, 2010 by in Technical

using System;
using System.Windows;
using System.Windows.Data;
using System.Globalization;
namespace Ravi.Infrastructure.Converters
{
///

/// This class converts boolean values for use in a
/// radio button scenario where you have a Yes/No or Active/Inactive situation
///

public class ConvertBoolForIsChecked : IValueConverter
{
#region Methods

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null || parameter == null)
return false;

return System.Convert.ToBoolean(value) == System.Convert.ToBoolean(parameter);
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
//If “No” is checked
if (System.Convert.ToBoolean(value) == (System.Convert.ToBoolean(parameter) == false))
return false;
else
{
//If “Yes” is checked
if(System.Convert.ToBoolean(value) == System.Convert.ToBoolean(parameter))
return true;
else
{
//inspecting a particular target where it isn’t checked
return DependencyProperty.UnsetValue;
}
}
}
#endregion Methods
}
}

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

12,871 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© All rights reserved to Cyberbrutus. 2012
credit

Switch to our mobile site