设置图像的构建操作属性

时间:2016-07-26 19:15:05

标签: c# wpf image

我有一个简单的问题。我想在按钮上添加图像,有一种情况我无法管理。在设计器中一切正常,但在调试模式下,按钮内没有任何图片的痕迹。我读到我必须将图像的Build Action属性设置为" Recourses"或"内容"但是我没有在解决方案资源管理器中显示这些图片,当我点击"显示所有文件时我可以看到它们但是它们有奇怪的图标而不是我在解决方案资源管理器中通常可以看到的那个图像而没有构建行动财产。

我应该以不同的方式添加图片吗?

<Button x:Name="loadButton" HorizontalAlignment="Left" Margin="955,0,0,443" Style="{DynamicResource SimpleButton}" VerticalAlignment="Bottom" Width="29" Height="27" FontFamily="Courier New" FontWeight="Bold" Click="loadButton_Click" Background="{x:Null}" BorderBrush="{x:Null}">


        <StackPanel Orientation="Horizontal">
            <Image x:Name="Load" Source="open-map.png"/>
        </StackPanel>

    </Button>
    <CheckBox x:Name="mode" Content="Tryb tworzenia" HorizontalAlignment="Left" Margin="30,292,0,0" VerticalAlignment="Top" FontSize="18.667" Foreground="#FFAC3333" FontFamily="Courier New" IsChecked="True"/>
    <Button x:Name="button1_Copy" HorizontalAlignment="Left" Margin="912,0,0,443" Style="{DynamicResource SimpleButton}" VerticalAlignment="Bottom" Width="29" Height="27" FontFamily="Courier New" FontWeight="Bold" Click="button1_Copy_Click" Background="{x:Null}" BorderBrush="{x:Null}">

        <StackPanel Orientation="Horizontal">
            <Image x:Name="Save" Source="save-icon.png"/>
        </StackPanel>

    </Button>

Solution Explorer

先谢谢

1 个答案:

答案 0 :(得分:1)

open-map.png等文件不属于C#项目,因此您无法设置任何属性。右键单击C#项目并将文件添加到项目中,然后您就可以设置其属性。