2012-04-27 122 views
1

我想從dll設置我的窗口圖標,但它的拋出錯誤。從WPF的dll設置窗口圖標

我有一個在JIMS.Resources.dll名爲JIMS.ico圖標我消耗這在我的窗口

<Window x:Class="JIMS.Home"   
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     
     Title="JIMS" WindowStyle="None" 
     Icon="/JIMS.Resources;component/JIMS.ico"> 
</Window> 

但它拋出一個異常

System.Windows.Markup.XamlParseException occurred 
    HResult=-2146233087 
    Message='Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '4' and line position '145'. 
    Source=PresentationFramework 
    LineNumber=4 
    LinePosition=145 
    StackTrace: 
     at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) 
     at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) 
     at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) 
     at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) 
     at JIMS.Home.InitializeComponent() in d:\JIMS\JIMS\Home.xaml:line 1 
     at JIMS.Home..ctor() in D:\JIMS\JIMS\Home.xaml.cs:line 25 
    InnerException: System.IO.IOException 
     HResult=-2146232800 
     Message=Cannot locate resource 'jims.ico'. 
     Source=PresentationFramework 
     StackTrace: 
      at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access) 
      at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access) 
      at System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream() 
      at System.IO.Packaging.PackWebResponse.GetResponseStream() 
      at System.IO.Packaging.PackWebResponse.get_ContentType() 
      at System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(Uri uri, Stream stream, BitmapCacheOption cacheOption, Guid& clsId, Boolean& isOriginalWritable, Stream& uriStream, UnmanagedMemoryStream& unmanagedMemoryStream, SafeFileHandle& safeFilehandle) 
      at System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy, Boolean insertInDecoderCache) 
      at System.Windows.Media.Imaging.BitmapFrame.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy) 
      at System.Windows.Media.ImageSourceConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) 
      at System.Windows.Baml2006.TypeConverterMarkupExtension.ProvideValue(IServiceProvider serviceProvider) 
      at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider) 
     InnerException: 
+0

長時間沒有答案 – 2012-04-27 21:53:21

+0

嗨,這是一個.net程序集?如果是這樣,它是如何宣佈的?資源,嵌入式資源,其他? – 2012-04-28 01:08:12

回答

3

具有以下嘗試:

Icon="pack://application:,,,/JIMS.Resources;component/JIMS.ico"

對於這樣的圖標公頃有待構建爲Resource