我在WPF项目的“图像”文件夹中有一些图像。它们在我的MainWindow.xaml窗口上解析得很好,但是当我在第二个窗口上引用相同的图像时,我得到了VS无法找到我正在引用的JPG文件的错误。好像系统正在我的C:\ ProgramFiles \目录中寻找文件。 MainWindow.xaml和我的第二个窗口有什么区别?
我尝试重新构建解决方案并重新输入路径,似乎没有任何帮助
图像参考:
<UniformGrid.Background>
<ImageBrush ImageSource="Images\black-diamond-plate.jpg" Stretch="UniformToFill" TileMode="Tile" Opacity=".25"/>
</UniformGrid.Background>
<UniformGrid.Background>
MainWindow.xaml图像可以在这里引用。
<Window x:Class="QCast.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:QCast"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
mc:Ignorable="d"
Title="home" Height="450" Width="800" WindowState="Maximized" Background="#FF313030" BorderBrush="Red" BorderThickness="2">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="SteelBrush.xaml"/>
<ResourceDictionary Source="ButtonnTemplates.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
图像:
</UniformGrid>
<UniformGrid VerticalAlignment="Stretch" Grid.Row="1">
<UniformGrid.Background>
<ImageBrush ImageSource="Images\black-diamond-plate.jpg" Stretch="UniformToFill" TileMode="Tile" Opacity=".25"/>
</UniformGrid.Background>
wRawMatEntry.xaml(在此处找不到图像的地方)
<Window x:Class="QCast.Windows.RawMatEntry"
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:QCast.Windows"
mc:Ignorable="d"
Title="RawMatEntry" Height="450" Width="800" Background="#FF313030" BorderBrush="Red" BorderThickness="2">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="SteelBrush.xaml"/>
<ResourceDictionary Source="ButtonnTemplates.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
图像参考:
</UniformGrid>
<UniformGrid VerticalAlignment="Stretch" Grid.Row="1">
<UniformGrid.Background>
<ImageBrush ImageSource="Images\black-diamond-plate.jpg" Stretch="UniformToFill" TileMode="Tile" Opacity=".25"/>
</UniformGrid.Background>
<Grid>
我更改了路径]
"Images\black-diamond-plate.jpg"
至:
".\Images\black-diamond-plate.jpg"
因为我的窗口在的子文件夹中,所以我必须引用项目本身的项目,然后它才能工作