WPF图像未加载 [英] WPF image does not load

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

问题描述

在预览中一切正常,但是当我编译时,没有图像.如果源中有问题,那么为什么它在预览窗口中显示?

In preview all good, but when I compiling, there is no image. If problem in source, so why it is showing in preview window?

 <Grid>
    <!-- Grid 4x3 -->
    <Grid.RowDefinitions>
        <RowDefinition Height="1*"></RowDefinition>
        <RowDefinition Height="0.5*"></RowDefinition>
        <RowDefinition Height="0.5*"></RowDefinition>
        <RowDefinition Height="0.7*"></RowDefinition>
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="0.2*"></ColumnDefinition>
        <ColumnDefinition Width="1*"></ColumnDefinition>
        <ColumnDefinition Width="0.2*"></ColumnDefinition>
    </Grid.ColumnDefinitions>

    <!-- Controls -->
        <!-- Row №1-->
    <Image Grid.Row="0" Grid.Column="1" Source="pack://siteoforigin:,,,/Resources/logo.png"></Image>
        <!-- Row №2-3 -->
    <StackPanel Grid.Row="1" Grid.Column="1" Grid.RowSpan="2">
        <Label Content="Вы заходите как..."></Label>
        <ComboBox>
            <ComboBoxItem Content="Клиент"></ComboBoxItem>
            <ComboBoxItem Content="Сотрудник"></ComboBoxItem>
        </ComboBox>
        <Label Content="ID"></Label>
        <TextBox></TextBox>
        <Label Content="Пароль"></Label>
        <PasswordBox></PasswordBox>
    </StackPanel>
    <!-- Row №4 -->
</Grid>

推荐答案

似乎您指定的图像未复制到输出目录.您可以通过两种方式解决此问题:
1)在属性网格中,将构建操作"设置为无",将复制到输出目录"设置为始终复制"(您需要执行此操作,因为siteoforigin URI在二进制文件位置中查找资源)
2)将构建操作"属性设置为资源",并使用 pack://application 绝对URI或相对URI(例如:< Image Source ="Resources/logo.png"/> )

Seems that the image you specified is not copied to the output directory. You can resolve the issue in two ways:
1) In the property grid set Build Action to "None" and Copy to Output Directory to "Copy always" (you need to do this because the siteoforigin URI seeks the resource in the binary file location)
2) Set the Build Action property to "Resource" and use the pack://application absolute URI or the relative URI (like this: <Image Source="Resources/logo.png"/> )

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

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