【发布时间】:2020-02-28 09:49:01
【问题描述】:
我的 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>
【问题讨论】:
-
这个问题非常有趣。谁能分辨出不存在的东西的区别?什么都没有比较?我认为您忘记发布代码以进行比较。确保图像资源的构建操作设置为 Resource.
-
检查镜像的构建动作。此外,您的
RawMatEntry窗口似乎位于不同的命名空间中。如果此命名空间映射到不同的文件夹,则调整您指定的文件路径。例如,路径可以是 "\..\Images\black-diamond-plate.jpg" 其中 .. 将一个目录移向根目录(向上一个文件夹)。
标签: wpf xaml embedded-resource