请有人可以帮忙。我在尝试编译XAML代码时遇到下面的异常。发生System.Windows.Markup.XamlParseException。微软视觉工作室社区2017
System.Windows.Markup.XamlParseException发生 的HResult = 0x80131501 消息= System.Windows.Baml2006.TypeConverterMarkupExtension '上提供值 '' 引发了异常。'行号“28”和行位置“22”。 源= PresentationFramework 堆栈跟踪: 在System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader,IXamlObjectWriterFactory writerFactory,布尔skipJournaledProperties,对象rootObject,XamlObjectWriterSettings设置,乌里基本URI) 在System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader (对象父组件,布尔closeStream) 对象组件对象组件对象组件对象组件对象组件对象组件对象组件对象组件对象组件,Uri resourceLocator) at c:\ users \ mypc \ documents \ visual studio 2017 \ Projects \ XAMLImage \ XAMLImage \ MainWindow.xaml中的XAMLImage.MainWindow.InitializeComponent():行1
内部异常1: IOException:找不到资源'images/tahoe_01.jpg'。
后面的代码的c#部分类的“InitializeComponent()”发生异常。下面是C#局部类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace XAMLImage
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
下面是XAML代码
<Window x:Class="XAMLImage.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:XAMLImage"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="604">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height = "1*"/>
<RowDefinition Height = "1*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Image Width = "200" VerticalAlignment = "Top" Margin = "30"/>
<Image Width = "200" Source = "Images\flow5.gif"
VerticalAlignment = "Top" Margin = "30" Opacity = "0.5"/>
</StackPanel>
<StackPanel Grid.Row = "1">
<Ellipse Height = "100"
Width = "200"
HorizontalAlignment = "Center"
Margin = "30">
<Ellipse.Fill>
<ImageBrush ImageSource = "Images\bubble.png" />
</Ellipse.Fill>
</Ellipse>
</StackPanel>
</Grid>
</Window>
有下图像的源URL和URL的ImageSource的图像刷元件的蓝色波浪线。我将鼠标悬停在上面,intellisense说“找不到文件”c:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Community \ Common7 \ IDE \ images%5Cmyfilename.gif'“(其中一个文件是一个gif,另一个是png)。我认为这些文件的位置是一个不确定的路径,但是我继续创建了这条路径上的URL,但是仍然会抛出异常。
请有人可以帮忙。我使用Microsoft Visual Studio 2017年社区
干杯
如果您编写ImageSource =“Images \ tahoe_01.jpg”,则该图像应位于解决方案下名为Images的文件夹中。有一个这样的文件夹吗? – Mishka
@Mishka感谢您的回复。我在你的评论后编辑了我的问题。路径是Images \ flow5.gif。是。我将它添加到我的解决方案中,仍然是异常抛出。我将它添加到我的项目中(我可以在XAML设计器中看到图像),但仍然是异常抛出。 – Evan
右键单击解决方案下的图像,然后单击以查看属性,图像的“构建动作”是什么? “复制到输出目录”的值是什么? – Mishka