/////////////////////////////////////////////////////////////////////////////// //Copyright (c) 2015, 北京探索者软件公司 //All rights reserved. //文件名称: BoolStringToBoolean.cs //文件描述: 布尔字符串转换成布尔值,使用转换器传入参数,主要用于前台绑定两个正反互斥的选项 //创 建 者: xls //创建日期: 2016-8-16 //版 本 号:1.0.0.0 //////////////////////////////////////////////////////////////////////////////// using System; using System.Globalization; using System.Windows.Data; namespace FWindSoft.Wpf { public class BoolStringToBoolean : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { object returnValue = false; if (parameter != null) { bool tempValue; bool.TryParse(parameter.ToString(), out tempValue); returnValue = tempValue && System.Convert.ToBoolean(value); } return returnValue; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { //if (value is bool || (bool) value) //{ //} bool tempValue; bool.TryParse(parameter.ToString(), out tempValue); return tempValue; } } }