zoukankan      html  css  js  c++  java
  • 深入浅出PF 学习笔记---TypeConverter

    1. StringToHumanTypeConverter类(从TypeConverter继承
    2. using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      
      namespace WpfStudy2018
      {
          /// <summary>
          /// 将string类型转成Human
          /// </summary>
          public class StringToHumanTypeConverter:TypeConverter
          {
              public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
              {
                  if (value is string)
                  {
                      Human h = new Human();
                      h.Name = value.ToString();
                      return h;
                  }
                  
                  return base.ConvertFrom(context, culture, value);
              }
          }
      }
      

        

    3. Human类
    4.  [TypeConverterAttribute(typeof(StringToHumanTypeConverter))]
          public class Human
          {
              public string Name
              {
                  get;
                  set;
              }
      
              public Human Child
              {
                  get;
                  set;
              }
          }
    5. 前端引用: xmlns:local="clr-namespace:WpfStudy2018"
    6. 前段代码:
      <Window.Resources>
              <local:Human x:Key="Snow" Name="zhouyg" Child="Jack"></local:Human>
        </Window.Resources>
    7. 后台代码:Human h =   this.FindResource("Snow") as Human;
  • 相关阅读:
    请说出这些测试最好由那些人员完成,测试的是什么?
    测试结束的标准是什么?
    你的测试职业发展目标是什么?
    elementui医疗
    医疗前端
    spring创建对象3种方式
    idea-git
    eclipse-git
    ArrayList01
    单体权限
  • 原文地址:https://www.cnblogs.com/sportdog/p/8522143.html
Copyright © 2011-2022 走看看