Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys

i want to add item + icon to listview i try this code :

C#
private void b2_Click_1(object sender, RoutedEventArgs e)
        {
            ListViewItem myItem = new ListViewItem();
            Image img = new Image();
            img.Source = new BitmapImage(new Uri("pack://application:,,,/Images/save.png"));
            myItem.Content = img;
            ListView1.Items.Add(myItem);

        }


and icon add in listview. but how can add textbox1.text + images in listview???
Posted
Updated 13-Jun-14 1:36am
v2

ListViewItem = img + textblock?

you set: myItem.Content = img;
If you want image + textblock you have to create datatemplate for listview item.

Example:
http://www.wpf-tutorial.com/listview-control/listview-data-binding-item-template/[^]
 
Share this answer
 
define itemtemplate of the listbox with image and text
HTML
<listbox.itemtemplate>
        <datatemplate>
            <stackpanel orientation="Horizontal">
                <image source="/Images/save.png" />
                <textblock text="{Binding FileName}" />
            </stackpanel>
        </datatemplate>
    </listbox.itemtemplate>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900