WPF图像无法加载[重复]

问题描述 投票:0回答:2

在预览中一切都很好,但是当我编译时,没有图像。如果源代码有问题,为什么它会在预览窗口中显示?

 <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>
.net wpf image xaml
2个回答
1
投票

似乎您指定的图像未复制到输出目录。您可以通过两种方式解决问题: 1)在属性网格中将Build Action设置为“None”并将Copy to Copy复制到“Always always”(您需要这样做,因为siteoforigin URI在二进制文件位置中搜索资源) 2)将Build Action属性设置为“Resource”并使用pack://application绝对URI或相对URI(如下所示:<Image Source="Resources/logo.png"/>


0
投票

尝试将源设置为此,看看它是否解决了您的问题。

<Image Source="/MonFitClub;component/Resources/logo.png"/>

如果我确实看到了正确的地方qazxsw poi是你的项目名称。

© www.soinside.com 2019 - 2024. All rights reserved.