开发者

C# WPF XAML Problem with icon in GridViewColumn

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" Disp开发者_开发知识库layMemberBinding="{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!


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>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜