日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

發(fā)布時間:2025/3/20 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPF ---- ​xmal 解析器没有办法解析类的TypeConverter 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

????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 不支持從字符串進行轉換。這個問題到目前為止還沒有解決。但是程序是可正常運行的。沒有運行問題。


轉載于:https://blog.51cto.com/6772017/1432317

總結

以上是生活随笔為你收集整理的WPF ---- ​xmal 解析器没有办法解析类的TypeConverter的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。