资源映像不显示WPF
我有3.png图片,我想把它们添加到网格上(简单地说) 我的两张照片正确地显示了,但第一张没有,我不知道为什么: 以下是我的app.xaml行,用于所有3张图片:资源映像不显示WPF,wpf,xaml,Wpf,Xaml,我有3.png图片,我想把它们添加到网格上(简单地说) 我的两张照片正确地显示了,但第一张没有,我不知道为什么: 以下是我的app.xaml行,用于所有3张图片: <BitmapImage x:Key="EditIcon" UriSource="Ressources\EdtIcon.png"/> <BitmapImage x:Key="DeleteIcon" UriSource="Ressources\DltIcon.png"/> <Bitm
<BitmapImage x:Key="EditIcon" UriSource="Ressources\EdtIcon.png"/>
<BitmapImage x:Key="DeleteIcon" UriSource="Ressources\DltIcon.png"/>
<BitmapImage x:Key="InterroIcon" UriSource="Ressources\InterroIcon.png"/>
以下是我将其中3个放入网格的方式:
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Ellipse Width="20" Height="20" VerticalAlignment="top" Margin="0,0,0,0" HorizontalAlignment="Center" MouseLeftButtonUp="ButtonComparerCorrection_Click">
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding InterroIcon}"/>
</Ellipse.Fill>
</Ellipse>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Ellipse Width="20" Height="20" VerticalAlignment="Top" Margin="0,0,0,0" HorizontalAlignment="Stretch" MouseLeftButtonUp="ButtonDeleteRow_Click">
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding DeleteIcon}"/>
</Ellipse.Fill>
</Ellipse>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Ellipse Width="20" Height="20" VerticalAlignment="top" Margin="1,0,0,1" HorizontalAlignment="Stretch" MouseLeftButtonUp="ButtonEditRow_Click">
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding EditIcon}"/>
</Ellipse.Fill>
</Ellipse>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
唯一没有出现的图像是第一张:InterroIcon
我检查了png文件的名称,它也是InterroIcon
在互联网上检查后,我进行了验证,生成操作为“资源”,副本设置为“如果更新”,通常这是解决问题的方法,但在我的情况下不是这样
这个问题的原因可能是什么
感谢您抽出时间
{Binding InterroIcon}
如果DataContext中有InterroIcon
属性,并且与ImageSource
类型兼容,则该属性将起作用
因为您已经声明了图像资源,所以使用它们更有意义(没有绑定错误,并且图像资源不属于MVVM体系结构中的DataContext):
此外,所有图片都在同一个文件夹中,当其他图片处于拉伸状态时,“水平对齐”设置为居中并不是我非常困惑的原因。InterroIcon是资源的关键。我希望{StaticResource InterroIcon}
,而不是{Binding InterroIcon}
。如果绑定起作用,那么就有一个不同的InterroIcon,使用StaticResource而不是绑定起作用,我对XAML知之甚少,但是在这种情况下,如果我没有其他两张图片的重复文件,那么绑定对它们起作用了吗?“绑定对它们起作用了吗”-这就是我要问的。它不是对资源的绑定,而是对某些属性的绑定。在projectI中进行搜索我有另一个类返回编辑和删除图标的位图图像,我正在收回该项目,而不是其中唯一的一个,因此我猜这一定是其他人的工作编辑:这是用来使图片可见或不取决于某些条件谢谢你的回答!
<ImageBrush ImageSource="{StaticResource InterroIcon}"/>
<ImageBrush ImageSource="{StaticResource DeleteIcon}"/>
<ImageBrush ImageSource="{StaticResource EditIcon}"/>