1.A, Silverlight字符串格式表
1.B, 价格格式转换器
1.C, 日期时间格式转换器
1.D, 图片路径转换器
1.A, Silverlight字符串格式表返回顶部 1,数字数据字符串格式 2,时间和日期字符串格式 3, 4, 更多 标准数字格式字符串 http://msdn.microsoft.com/zh-cn/library/dwhawy9k(v=vs.80).aspx 1.B, 价格格式转换器返回顶部 1,PriceConverter.cs class="code_img_closed" src="/Upload/Images/2013111923/0015B68B3C38AA5B.gif" alt="" />logs_code_hide('cee43af7-92ee-46ce-9709-92e9370b0905',event)" src="/Upload/Images/2013111923/2B1B950FA3DF188F.gif" alt="" />using System; using System.Globalization; using System.Windows.Data; namespace SLYlbtechApp.DBUtility.Converter { /// <summary> /// 价格格式转换器 /// 20:53 2013/11/18 /// </summary> public class PriceConverter:IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double price = (double)value; return price.ToString("C", culture); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { string price = value.ToString(); double result; if (double.TryParse(price, NumberStyles.Any, culture, out result)) { return result; } return value; } } }View Code
4,
1.C, 日期时间格式转换器返回顶部 1,DateConverter.cs 日期格式转换器【yyyy-MM-dd】using System; using System.Globalization; using System.Windows.Data; namespace SLYlbtechApp.DBUtility.Converter { /// <summary> /// 日期格式转换器【yyyy-MM-dd】 /// </summary> public class DateConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DateTime date = (DateTime)value; return date.ToString("yyyy-MM-dd"); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { string date = value.ToString(); DateTime result; if (DateTime.TryParse(date, culture, DateTimeStyles.None, out result)) { return result; } return value; } } }View Code
2,DateTimeConverter.cs 日期和时间 格式转换器【yyyy-MM-dd hh:mm:ss】
using System; using System.Globalization; using System.Windows.Data; namespace SLYlbtechApp.DBUtility.Converter { /// <summary> /// 日期和时间 格式转换器【yyyy-MM-dd hh:mm:ss】 /// </summary> public class DateTimeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DateTime date = (DateTime)value; return date.ToString("yyyy-MM-dd hh:mm:ss"); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { string date = value.ToString(); DateTime result; if (DateTime.TryParse(date, culture, DateTimeStyles.None, out result)) { return result; } return value; } } }View Code
3,DateCnConverter.cs 日期格式转换器【yyyy年MM月dd日】
using System; using System.Globalization; using System.Windows.Data; namespace SLYlbtechApp.DBUtility.Converter { /// <summary> /// 日期格式转换器【yyyy年MM月dd日】 /// </summary> public class DateCnConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DateTime date = (DateTime)value; return date.ToString("yyyy年MM月dd日"); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { string date = value.ToString(); DateTime result; if (DateTime.TryParse(date, culture, DateTimeStyles.None, out result)) { return result; } return value; } } }View Code
4,DateTimeCnConverter.cs 日期和时间 格式转换器【yyyy年MM月dd日 hh:mm:ss】
using System; using System.Globalization; using System.Windows.Data; namespace SLYlbtechApp.DBUtility.Converter { /// <summary> /// 日期和时间 格式转换器【yyyy年MM月dd日 hh:mm:ss】 /// </summary> public class DateTimeCnConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DateTime date = (DateTime)value; return date.ToString("yyyy年MM月dd日 hh:mm:ss"); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { string date = value.ToString(); DateTime result; if (DateTime.TryParse(date, culture, DateTimeStyles.None, out result)) { return result; } return value; } } }View Code
5,
1.D, 图片路径转换器返回顶部 1,ImagePathConverter.csusing System; using System.Windows.Data; using System.Globalization; using System.Windows.Browser; using System.Windows.Media.Imaging; namespace SLYlbtechApp.DBUtility.Converter { /// <summary> /// 图片路径转换器 /// </summary> public class ImagePathConverter { string rootUri; /// <summary> /// 跟 Uri /// </summary> public string RootUri { get { return rootUri; } set { rootUri = value; } } public ImagePathConverter() { string uri = HtmlPage.Document.DocumentUri.ToString(); //Remove the web page from the current URI to get the roor URI. //删除web页面从当前URI获取roor URI。 rootUri = uri.Remove(uri.LastIndexOf('/'), uri.Length - uri.LastIndexOf('/')); } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string imagePath = RootUri + "/" + (string)value; return new BitmapImage(new Uri(imagePath)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { //Images aren't editable, so there's no need to support ConvertBack. //图片没有可编辑的,所以没有必要支持ConvertBack。 throw new NotImplementedException(); } } }View Code
4,
1.E,返回顶部 1.F,返回顶部 1.G,返回顶部 1.H,返回顶部 1.R,返回顶部 作者:ylbtech