【问题标题】:XamlParseException on setting icon from xaml on WinXP/WinServer2003?在 WinXP/WinServer2003 上从 xaml 设置图标时出现 XamlParseException?
【发布时间】:2012-03-22 18:18:39
【问题描述】:

所以...很奇怪,我的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 中运行良好,并在窗口上正确显示了图标。

【问题讨论】:

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


    【解决方案1】:

    我曾经遇到过这种情况,因为使用了一个全彩色的高清图标,XP 客户端似乎无法正确处理它。减少了图标的颜色数量并且效果很好。

    【讨论】:

    • OOoohhhh..终于可以工作了....我将尺寸减小到 48,颜色减小到 256...最后...谢谢! +1
    猜你喜欢
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-27
    • 1970-01-01
    • 2012-05-22
    相关资源
    最近更新 更多