关于在WinXP / WinServer2003上从xaml设置图标的XamlParseException?

时间:2012-03-22 18:18:39

标签: c# wpf xaml windows-xp windows-server-2003

所以...很奇怪,我在Window控件中有以下代码来设置窗口图标,它在Win7机器上完美运行:

  Icon="./Resources/MyWPF.ico"

<Window x:Class="MyWPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    xmlns:mdi="clr-namespace:WPF.MDI;assembly=WPF.MDI"
    xmlns:misc="clr-namespace:MyWPF.Tools.Misc"
    xmlns:View="clr-namespace:MyWPF.View"
    xmlns:ScriptListView="clr-namespace:MyWPF.Tools.ScriptViewer.View"
    Title="Voysus System" WindowStartupLocation="CenterScreen" MinWidth="800"     MinHeight="600"            
    Icon="./Resources/MyWPF.ico"
    x:Name="_Root" Closing="_Root_Closing"> 

但是当它在Server 2003 Standard x64 / WinXP Pro上运行时,两者都给我错误:

System.Windows.Markup.XamlParseException
Source: PresentationFramework
Message: Cannot convert string './Resources/MyWPF.ico' in attribute 'Icon' to object of type 'System.Windows.Media.ImageSource'. The image decoder cannot decode the image. The image might be corrupted.  Error at object '_Root' in markup file 'VoysusSystem;component/mainwindow.xaml' Line 8 Position 95.
StackTrace:    at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
   at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
   at System.Windows.Markup.XamlTypeMapper.ParseProperty(Object targetObject, Type propType, String propName, Object dpOrPiOrFi, ITypeDescriptorContext typeContext, ParserContext parserContext, String value, Int16 converterTypeId)
   at System.Windows.Markup.BamlRecordReader.ParseProperty(Object element, Type propertyType, String propertyName, Object dpOrPi, String attribValue, Int16 converterTypeId)
   at System.Windows.Markup.BamlRecordReader.ReadPropertyRecordBase(String attribValue, Int16 attributeId, Int16 converterTypeId)
   at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
   at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
   at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
   at System.Windows.Markup.TreeBuilder.Parse()
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at VoysusSystem.MainWindow.InitializeComponent() in c:\SandBox\MyWPF\MyWPF\MainWindow.xaml:line 1
   at VoysusSystem.MainWindow..ctor() in C:\SandBox\MyWPF\MyWPF\MainWindow.xaml.cs:line 93
   at VoysusSystem.ViewModel.LoginViewModel.Login(String strPassword) in C:\SandBox\MyWPF\MyWPF\Main\ViewModel\LoginViewModel.cs:line 147
   at VoysusSystem.ViewModel.LoginViewModel.<.ctor>b__2(String str) in C:\SandBox\MyWPF\MyWPF\Main\ViewModel\LoginViewModel.cs:line 97

我还尝试使用Icon="/MyWPF;component/Resources/MyWPF.ico"

但它也给我带来了同样的错误。

删除该行后,代码停止在WinXP和WinServer2003上抛出异常。

同样,这些代码在Win7中运行正常,并在Window上正确显示图标。

1 个答案:

答案 0 :(得分:2)

它曾经发生在我身上,因为使用了一个高清的彩色图标,这似乎没有被XP客户端正确处理。减少了图标的颜色数量,并且工作正常。