C# 带有图像的WPF按钮不';不出现

C# 带有图像的WPF按钮不';不出现,c#,wpf,image,button,C#,Wpf,Image,Button,我正在使用几个小时前在一个问题上找到的以下代码使按钮具有图像: <Button Name="bPlay" Height="70" Width="70" Margin="359,480,349,11"> <Button.Template> <ControlTemplate> <Border HorizontalAlignment="Cen

我正在使用几个小时前在一个问题上找到的以下代码使按钮具有图像:

            <Button Name="bPlay" Height="70" Width="70" Margin="359,480,349,11">
            <Button.Template>
                <ControlTemplate>
                    <Border HorizontalAlignment="Center" VerticalAlignment="Center">
                        <Image Source="pack://siteoforigin:,,,/Resources/play.bmp" Width="70" Height="70" />
                    </Border>
                </ControlTemplate>
            </Button.Template>
        </Button>


问题是,由于某些原因,它在VisualStudio上看起来不错,但当我运行程序时,这些按钮不会出现。我找不到问题,有点卡住了。图像
play.bmp
显然已添加到参考资料中,但我仍然不知道问题出在哪里,谢谢

试着简化你的代码,也许只是把图像拉出来看看是否会显示出来

<Button Name="bPlay" Height="70" Width="70" Margin="359,480,349,11">
    <Image Source="pack://siteoforigin:,,,/Resources/play.bmp" Width="70" Height="70" />
</Button>

URI中的“siteoforigin”指示文件必须位于相对于执行程序集目录的给定路径中。您的可执行文件很可能位于bin/Debug文件夹中。它正在查找可执行文件的子目录,该子目录可能不存在(“bin/Debug/Resources/play.bmp”)

如果要以这种方式链接到文件,则必须告诉Visual Studio将其复制到输出文件夹(从“属性”窗格)。或者自己复制


或者更好的是,您应该将它作为一种资源进行链接,它将嵌入到应用程序中。在“属性”窗格中将文件的生成类型设置为“资源”,并使用项目文件夹中的相对路径链接到该文件。在这种情况下,请在XAML中逐字写下“Resources/play.bmp”。

由于某种原因,在我尝试时没有图像出现(我可以看到按钮,但上面没有图像)@waclock别忘了@waclock good!记住要帮助社区和访客找到一个公认的答案:)