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 不支持從字符串進行轉換。這個問題到目前為止還沒有解決。但是程序是可正常運行的。沒有運行問題。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。