WPF ---- xmal 解析器没有办法解析类的TypeConverter
????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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ExtJs FormPanel布局
- 下一篇: java解析XML获取城市代码