WPF中使用图像和图标 [英] Using Images and Icons in WPF

查看:387
本文介绍了WPF中使用图像和图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个图标在我的WPF应用程序,以及其他一些事情的图像,但我不断收到错误的设计观说的东西,如路径x是不是一个有效的资源或无法找到。 - 其中路径-X是什么形象我想使用的路径

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 ;)

不过,届时,决定给不给我的错误了。所以,我说干就干,点击运行(F5),来看看我的新图标在标题栏中。只有将面临此兽:

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   发生消息='上提供的价值   System.Windows.Baml2006.TypeConverterMarkupExtension   引发了异常。行号5   并线的位置'50'。
  来源= presentationFramework
  行号= 5 LinePosition = 50
  堆栈跟踪:          在System.Windows.Markup.XamlReader.RewrapException(异常   E,IXamlLineInfo lineInfo,乌里   基本URI)          在System.Windows.Markup.WpfXamlLoader.Load(的XamlReader   的XamlReader,IXamlObjectWriterFactory   writerFactory,布尔   skipJournaledProperties,对象   rootObject,XamlObjectWriterSettings   设置,开放的基本URI)          在System.Windows.Markup.WpfXamlLoader.LoadBaml(的XamlReader   的XamlReader,布尔   skipJournaledProperties,对象   rootObject,XamlAccessLevel   ACCESSLEVEL,乌里基本URI)          在System.Windows.Markup.XamlReader.LoadBaml(流   流,ParserContext parserContext,   对象父,布尔closeStream)          在System.Windows.Application.LoadComponent(对象   组件,乌里resourceLocator)          在One_Stop_Management.MainWindow.InitializeComponent()   在C:\用户\杰森\文档\ Visual   Studio 2010的\项目\一站式   管理\一站式   管理\ MainWindow.xaml:1号线          在One_Stop_Management.MainWindow..ctor()   在C:\用户\杰森\文档\ Visual   Studio 2010的\项目\一站式   管理\一站式   管理\ MainWindow.xaml.cs:行25   的InnerException信息:System.IO.IOException          消息=无法找到资源图像/的favicon.ico。          来源= presentationFramework          堆栈跟踪:               在MS.Internal.AppModel.ResourcePart.GetStreamCore(的FileMode   模式,FileAccess的访问)               在System.IO.Packaging.PackagePart.GetStream(的FileMode   模式,FileAccess的访问)               在System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream()               在System.IO.Packaging.PackWebResponse.GetResponseStream()               在System.IO.Packaging.PackWebResponse.get_ContentType()               在System.Windows.Media.Imaging.BitmapDe coder.SetupDe coderFromUriOrStream(URI   URI,流流,BitmapCacheOption   cacheOption,的Guid和放大器; CLSID,布尔和放大器;   isOriginalWritable,流和放大器; uriStream,   UnmanagedMemoryStream和放大器;   unmanagedMemoryStream,SafeFileHandle和放大器;   safeFilehandle)               在System.Windows.Media.Imaging.BitmapDe coder.CreateFromUriOrStream(URI   基本URI,开放的URI,流流,   BitmapCreateOptions createOptions,   BitmapCacheOption cacheOption,   RequestCachePolicy uriCachePolicy,   布尔insertInDe coderCache)               在System.Windows.Media.Imaging.BitmapFrame.CreateFromUriOrStream(URI   基本URI,开放的URI,流流,   BitmapCreateOptions createOptions,   BitmapCacheOption cacheOption,   RequestCachePolicy uriCachePolicy)               在System.Windows.Media.ImageSourceConverter.ConvertFrom(ITypeDescriptorContext   背景下,CultureInfo的文化,对象   值)               在System.Windows.Baml2006.TypeConverterMarkupExtension.ProvideValue(的IServiceProvider   服务提供者)               在MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(的MarkupExtension   我的IServiceProvider的ServiceProvider)          的InnerException:

"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: "

为什么这件事情给我的态度?我只是想插入图片...

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

下面是制作的图标,当我尝试添加使用属性面板中图标的XAML:

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

使用属性面板中我甚至不能添加一个图标,下面是错误它给了我。

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

推荐答案

我很抱歉,我不能提供更多的帮助。在阅读您的问题起初我以为这会是只是一个类型不匹配,就像你在哪里指定的字符串时,它本来是一个图像。这个问题似乎是一个有多种可能的解决方案。而不是列出所有这些的我只是连你的<一个href="http://connect.microsoft.com/VisualStudio/feedback/details/533882/provide-value-on-system-windows-baml2006-typeconvertermarkupextension-threw-an-exception"相对=nofollow> Microsoft连接页面,有他们在这的。

I'm sorry I can't be more helpful. On reading your question at first I thought it'd be just a type mismatch, like where you were specifying a string when it was meant to be an image. The issue seems to be one that has multiple possible resolutions. Instead of listing them all I'll just link you to the Microsoft Connect page that has them on it.

这篇关于WPF中使用图像和图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆