views:

488

answers:

2

I've created a ListView with a GridView component in it. Now trying to fill one of the cells with an icon (PNG) like in the code sample below (save_icon.png):

<ListView.View>
    <GridView>
        <GridViewColumn Header="Date" Width="Auto" DisplayMemberBinding="{Binding Date}" />
        <GridViewColumn Header="Time" Width="Auto" DisplayMemberBinding="{Binding Time}" />
        <GridViewColumn Header="FriendlyName" Width="Auto" DisplayMemberBinding="{Binding FriendlyName}" />
        <GridViewColumn Width="Auto">
            <Image Source="save_icon.png" />
        </GridViewColumn>
    </GridView>
</ListView.View>

Visual Studio gives me an error on the line, where i put the icon into the column (ERROR: "Error 35: The file save_icon.png is not part of the project or its 'Build Action' property is not set to 'Resource'.") I added the icon to the project as a resource and when i start the app, everything works (the icon appears at the right place). But the WPF designer window can't be reloaded and i'm not able to see changes in the designer, when i change the XAML code.

Can somebody explain this error or am i doing something wrong?

Thanks for every hint in advance!

A: 

I believe it is because you have an underscore in your image filename. Try removing the underscore and rebuilding.

billb
Thanks four your answer.Unforunately it didn't solve my problem :-( I removed all the icons from the project, renamed them (now without any special chars) and added them as new icons to the project resources... the error occurs like before: "Error 35: The file save_icon.png is not part of the project or its 'Build Action' property is not set to 'Resource'."That makes absolutely no sense to me... The icon is part of the project, it's build action is set to "Resource" and it appears when the app is running. But i can't use the wpf designer, because it does not reload because of the error.
Alex
Sorry that didn't help.Did you rebuild all? Also, I see there are reports of people recreating the project from scratch and adding the image files and it working. I did some combination of these things and got it to work. I hear the xaml editor is better in VS 2010. Let's hope.
billb
Yes, I rebuilded the whole project (I forgot to mention it above). I hope for a better XAML Editor in VS 2010, too. The one in VS 2008 sometimes does really strange things. Thanks anyway!
Alex
I would try recreating the project from scratch as well. Like I said, that seemed to help some people who also had this problem. If that doesn't work, I'm out of suggestions.
billb
A: 

I found a solution for my problem. Just use a Cell- and DataTemplate inside of a GridViewColumn. The follwoing XAML-Code-Snippet does exactly what i need and the wpf designer reloads without any problems:

<ListView.View>
    <GridView>
        <GridViewColumn Header="Date" Width="Auto" DisplayMemberBinding="{Binding Date}" />
        <GridViewColumn Header="Time" Width="Auto" DisplayMemberBinding="{Binding Time}" />
        <GridViewColumn Header="FriendlyName" Width="Auto" DisplayMemberBinding="{Binding FriendlyName}" />
        <GridViewColumn Width="Auto">
            <GridViewColumn.CellTemplate>
              <DataTemplate>
                     <Image Source="Resources\saveicon.png"></Image>
              </DataTemplate>
            </GridViewColumn.CellTemplate>
        </GridViewColumn>
    </GridView>
</ListView.View>
Alex