Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Images and Icons in WPF

I am trying to use an Icon in my WPF application, and some images for other things, but I keep getting errors from the Designer View saying stuff like "path-x is not a valid resource or cannot be found." - where "path-x" is the path of whatever image I am trying to use.

If it were looking in the right place, I bet it'd find it ;)

BUT, then, it decided to not give me that error anymore. So, I went ahead and clicked Run (F5), to see my new Icon in the title bar. Only to be confronted with this beast:

"System.Windows.Markup.XamlParseException occurred Message='Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '5' and line position '50'.
Source=PresentationFramework
LineNumber=5 LinePosition=50
StackTrace: at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri) 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 One_Stop_Management.MainWindow.InitializeComponent() in c:\Users\Jason\Documents\Visual Studio 2010\Projects\One Stop Management\One Stop Management\MainWindow.xaml:line 1 at One_Stop_Management.MainWindow..ctor() in C:\Users\Jason\Documents\Visual Studio 2010\Projects\One Stop Management\One Stop Management\MainWindow.xaml.cs:line 25 InnerException: System.IO.IOException Message=Cannot locate resource 'images/favicon.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: "

Exception at runtime while trying to use an icon for my titlebar!

Why is this thing giving me attitude? I'm just trying to insert an image...

Updates

Here is the XAML that was produced for the icon when I tried to add the Icon using the Properties Pane:

<Fluent:RibbonWindow x:Class="One_Stop_Management.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Fluent="clr-namespace:Fluent;assembly=Fluent"
        Title="One Stop Management" Height="727" Width="1208" Icon="Resources\favicon.ico">

Latest Update

enter image description here

I can't even add an icon using the properties pane, below is the error it gives me.

like image 499
βӔḺṪẶⱫŌŔ Avatar asked Apr 08 '11 23:04

βӔḺṪẶⱫŌŔ


People also ask

How to Add Icon to WPF project?

To add an icon to a project, right click on the project name in Solution Explorer. Right click will open Add Items menu. Select Add >> New Item. Now on Installed Templates, select Icon File (see Figure 1) and click Add.


1 Answers

Setting BuildAction to Resource in resource Properties solved this problem.

Greets

like image 51
user3173185 Avatar answered Oct 04 '22 19:10

user3173185