您好,登錄后才能下訂單哦!
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 不支持從字符串進行轉(zhuǎn)換。這個問題到目前為止還沒有解決。但是程序是可正常運行的。沒有運行問題。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。