图像在 WPF 2015 中不可见 [英] Image not visible in WPF 2015

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

问题描述

我无法在 WPF(Visual Studio Community Edition 2015)中显示图像.

I'm having some difficulty getting an image to display in WPF, Visual Studio Community Edition 2015.

第一个问题涉及图像的源"属性中缺少对话框.VS 的 WPF 教程展示了一种在源属性下浏览文件的方法.这在 VS 2015 社区版下似乎不是一个选项.有什么办法可以启用这个功能吗?还是在社区"版中没有启用?

The first issue involves a lack of dialog in the "Source" property for the image. WPF Tutorials of VS show a way to browse for the file under the source property.This does not appear to be an option under VS 2015 Community edition. Is there any way to enable this feature? Or is it not enabled in the "Community" edition?

第二个问题是,图像在运行时不可见,但在设计器中可见.以前的帖子建议将此图像的构建操作"启用为资源".似乎有许多文件可以设置构建操作:如果我将 MainWindow.xaml 文件设置为 BuildAction->Resource,我会收到以下错误:

The second issue is, the image is not visible at run time, but visible in the designer. Previous posts suggest to enable the "Build Action" for this image to "Resource". There seems to be number of files to set the Build Action on: If I set the MainWindow.xaml file to BuildAction->Resource I get the following error:

错误 CS0103 当前上下文中不存在名称InitializeComponent"

.... 如果我尝试将任何其他文件设置为 BuildAction->Resource,我会收到以下错误:

.... If I try to set any other file to BuildAction->Resource I get the following error:

标记文件无效.指定带有 .xaml 扩展名的源标记文件.

.. 如果不删除解决方案并从头开始,我似乎无法恢复.

.. And I seem unable to recover without deleting the solution and starting from scratch.

这是 XAML 代码

<Window x:Class="WR.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Demo" Height="350" Width="300" >
<Grid>
    <ListBox Name="DemoListBox" Margin="15">
          <Image x:Name="Image1" Source="/resources/facebook.png">
          </Image>
    </ListBox>
</Grid>

提前致谢

推荐答案

BuildAction->Resource 应该为文件 facebook.png 设置

BuildAction->Resource should be set for file facebook.png

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

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