日期:2014-05-17 浏览次数:20698 次
public class MyTextBox : TextBox
{
[TypeConverter(typeof (IpAddrConverter))]
public MyIPAddress RemoteIP
{
get { return (MyIPAddress)this.GetValue(RemoteIPProperty); }
set { this.SetValue(RemoteIPProperty, value); }
}
private static readonly DependencyProperty RemoteIPProperty = DependencyProperty.Register("RemoteIP",
typeof(MyIPAddress), typeof (MyTextBox), new PropertyMetadata(new MyIPAddress()));
}
public class MyIPAddress : IPAddress
{
public MyIPAddress() : base(0) { }
public MyIPAddress(IPAddress ip) : base(ip.Address) { }
}
public class IpAddrConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof (string)) return true;
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)