运行时未显示来自资源的WPF图像

时间:2019-04-19 17:39:37

标签: c# wpf image resources runtime

我试图将项目资源中的PNG图像添加到WPF窗口中,但是即使XAML预览中显示了PNG图像,一旦运行项目(调试模式),图像也会丢失。

我已经在线阅读了一些建议,但没有用: Source =“ pack:// siteoforigin:,, // Resources / 64.png”:运行时未显示图片

Source =“ pack:// application:,,, / Resources / 64.png”:运行时未显示图片

Source =“ / FloraDD; component / Resources / 64.png”:运行时未显示图像(FloraDD是我的项目)

Source =“ {StaticResource Leaf64}”(和)                    (来自App.xaml):异常DirectoryNotFoundException:找不到路径“ C:\ Users \ Sergio \ source \ repos \ FloraDD \ FloraDD \ bin \ Debug \ Resources \ 64.png”的一部分。 System.Windows.Markup.XamlParseException:``'System.Windows.Media.Imaging.BitmapImage'的初始化引发了异常。”行号“ 8”和行位置“ 37”。

我无法在图片的属性中设置任何构建操作,因为缺少此属性

<Window x:Class="FloraDD.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:FloraDD"
        mc:Ignorable="d"
        Title="{x:Static local:Constants.AppName}" Height="450" Width="800" Background="GhostWhite" Loaded="Window_Loaded" Icon="leaf.ico">
    <DockPanel LastChildFill="True">
        <Grid DockPanel.Dock="Top" Height="50">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                    <GradientStop Color="ForestGreen" Offset="0.0"></GradientStop>
                    <GradientStop Color="Transparent" Offset="1.0"></GradientStop>
                </LinearGradientBrush>
            </Grid.Background>
            <TextBlock Grid.Row="0" Grid.Column="1" Text="{x:Static local:Constants.AppFullName}" FontSize="24" FontWeight="Bold"  HorizontalAlignment="Center" VerticalAlignment="Center"/>
            <Image Grid.Row="0" Grid.Column="2" Source="pack://siteoforigin:,,,/Resources/64.png" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5"/>
            <!--ImageBrush Grid.Row="0" Grid.Column="2" ImageSource=""/FloraDD;component/Resources/64.png"/-->
        </Grid>
    '
    '
    '
    '
    </DockPanel>
</Window>

0 个答案:

没有答案