WPF ---- ​xmal 解析器没有办法解析类的TypeConverter

发布时间:2020-06-29 13:07:32 作者:neeky51
来源:网络 阅读:2233

    xmal 解析器没有办法解析类的TypeConverter.代码如下

    页面代码:

<Window x:Class="WpfApplication_xmln.Windows.ConvertWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:codes="clr-namespace:WpfApplication_xmln.Codes"

        Title="ConvertWindow" Height="300" Width="300">

    <Window.Resources>

        <codes:Human x:Key="scHuman" Name="NiNi" Child="HeHe"></codes:Human>

    </Window.Resources>

    <Grid>

        <Button Margin="50,50,50,50" Click="Button_Click" Content="this is the button" Background="Violet"></Button>

    </Grid>

</Window>

    后台代码:

    [TypeConverterAttribute(typeof(StringToHumanTypeConvert))]

    class Human

    {

        public string Name { get; set; }

        public Human Child { get; set; }

    }


    class StringToHumanTypeConvert : TypeConverter// using System.System.ComponentModel;

    {

        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)

        {

            if (value != null)

            {

                Human h = new Human();

                h.Name = value.ToString();

                return h;

            }

            return base.ConvertFrom(context, culture, value);

        }

    }

        private void Button_Click(object sender, RoutedEventArgs e)

        {

            Human h = this.FindResource("scHuman") as Human;

            MessageBox.Show(h.Child.Name);

        }


    错误1“Human”的 TypeConverter 不支持从字符串进行转换。这个问题到目前为止还没有解决。但是程序是可正常运行的。没有运行问题。


推荐阅读:
  1. C#中WPF依赖属性的正确学习方法
  2. WPF如何自定义ProgressBar滚动条样式

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

wpf 解析器 xmal

上一篇:SQL Server 2012安装配置(Part4 )

下一篇:NSAutoreleasePool初始化语句必须是第一条执行语句

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》