C# WPF XAML GridViewColumn 中的图标问题
我创建了一个 ListView,其中包含 GridView 组件。现在尝试用图标 (PNG) 填充其中一个单元格,如下面的代码示例 (save_icon.png) 所示:
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="Auto" DisplayMemberBinding="{Binding Date}" />
<GridViewColumn Header="Time" Width="Auto" DisplayMemberBinding="{Binding Time}" />
<GridViewColumn Header="FriendlyName" Width="Auto" DisplayMemberBinding="{Binding FriendlyName}" />
<GridViewColumn Width="Auto">
<Image Source="save_icon.png" />
</GridViewColumn>
</GridView>
</ListView.View>
Visual Studio 在线上出现错误,我将图标放入列中(错误:“错误 35”) :文件 save_icon.png 不是项目的一部分,或其“构建操作”属性未设置为“资源”。”)我将图标作为资源添加到项目中,当我启动应用程序时,一切正常(图标出现在正确的位置)。但是当我更改 XAML 代码时,WPF 设计器窗口无法重新加载,并且我无法看到设计器中的更改。
有人可以解释这个错误还是我做错了什么?
感谢您提前提供的每一个提示!
I've created a ListView with a GridView component in it. Now trying to fill one of the cells with an icon (PNG) like in the code sample below (save_icon.png):
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="Auto" DisplayMemberBinding="{Binding Date}" />
<GridViewColumn Header="Time" Width="Auto" DisplayMemberBinding="{Binding Time}" />
<GridViewColumn Header="FriendlyName" Width="Auto" DisplayMemberBinding="{Binding FriendlyName}" />
<GridViewColumn Width="Auto">
<Image Source="save_icon.png" />
</GridViewColumn>
</GridView>
</ListView.View>
Visual Studio gives me an error on the line, where i put the icon into the column (ERROR: "Error 35: The file save_icon.png is not part of the project or its 'Build Action' property is not set to 'Resource'.") I added the icon to the project as a resource and when i start the app, everything works (the icon appears at the right place). But the WPF designer window can't be reloaded and i'm not able to see changes in the designer, when i change the XAML code.
Can somebody explain this error or am i doing something wrong?
Thanks for every hint in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决我的问题的方法。只需在 GridViewColumn 内使用 Cell- 和 DataTemplate 即可。下面的 XAML-Code-Snippet 正是我所需要的,并且 wpf 设计器重新加载没有任何问题:
I found a solution for my problem. Just use a Cell- and DataTemplate inside of a GridViewColumn. The follwoing XAML-Code-Snippet does exactly what i need and the wpf designer reloads without any problems:
我相信这是因为你的图像文件名中有下划线。尝试删除下划线并重建。
I believe it is because you have an underscore in your image filename. Try removing the underscore and rebuilding.