WPF ---- xmal 解析器没有办法解析类的TypeConverter
????xmal 解析器沒(méi)有辦法解析類(lèi)的TypeConverter.代碼如下
????頁(yè)面代碼:
<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>
????后臺(tái)代碼:
? ? [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);
? ? ? ? }
????錯(cuò)誤1“Human”的 TypeConverter 不支持從字符串進(jìn)行轉(zhuǎn)換。這個(gè)問(wèn)題到目前為止還沒(méi)有解決。但是程序是可正常運(yùn)行的。沒(méi)有運(yùn)行問(wèn)題。
轉(zhuǎn)載于:https://blog.51cto.com/6772017/1432317
總結(jié)
以上是生活随笔為你收集整理的WPF ---- xmal 解析器没有办法解析类的TypeConverter的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: ExtJs FormPanel布局
- 下一篇: OutOfMemoryError与Sta