Files
06-Note/WPF/TypeConvert.md
sherlockforrest bf2ed2e31f 更新
2023-06-20 09:22:53 +08:00

680 B

类型转换

[typeconvert(typeof(stringtohumanTypeConvert))]
public class Human
{
    public string Name {get; set; }
    public Human Child {get; set; }
}
<windows.resource>
    <local:Human x:key="human" Child="ABC"/>
</windows.resource>
public class stringtohumanTypeConvert:typeconvert
{
    public override object convertfrom(Itypedescriptioncontext context,system.globalization.culture.CultureInfo culture,object value)
    {
        if(value is string)
        {
            Human h=new Human();
            h.Name=value as string;
            return h;
        }
        return base.convertfrom(context, culture,value);
    }
}