views:

88

answers:

5

I would like to fill my ListView with do aligned elements, a little icon (either a confirm mark or a cross) and a string which contains the result of a question (Right / Wrong, that's why icon).

daInserire = new ListViewItem();
daInserire.Foreground = new SolidColorBrush(Colors.DarkGreen);
daInserire.Content = "Giusto: "+ straniero.Text + " = " + vocItaliano[current];
daInserire.HorizontalContentAlignment = HorizontalAlignment.Center;
daInserire.FontSize = 18;
//...
listViewConInfo.Items.Add(daInserire);

This works perfectly, I'd like to add before the string, on the same line an image.

+1  A: 

Looks like you're using WPF, so you'll need to create a StackPanel for your Content property and add the Image and a Label to that StackPanel.

Simon Steele
Yeah, I thought that, but... How to do that?
Girildo
A: 

That's ok, I did that :)

Girildo
Best to add this as a comment to my answer, and then mark my answer as accepted!
Simon Steele
Thanks for the tips :)
Girildo
A: 

Can you copy the code of your solution ?

ScenicGA
A: 
 ListView lV = new listView(); 
 ListViewItem Item = new ListViewItem(); 
 WrapPanel wrap = new WrapPanel(); 
 Image image = new image();
 image.Source = <<yourSource>>;
 Label label = new Label();
 label.Content = "W/E you want";
 wrap.Children.Add(image);
 wrap.Children.Add(label);
 Item.Content = wrap;
 lV.Items.Add(Item); 
Girildo
A: 

Thanks for your reply.

Any Idea how to do this using MVVM ? I have this working code. Now I need to add an image for every item.

What type should I use to do that to be able to bind to ListView ?

My code looks like this :

View.xaml

viewModel.cs public class EViewModel { private EModel m_e; public List EWList { get { return m_e.EWList; } set { if (m_e.EWList== value) { return; } m_e.EWList= value; base.OnPropertyChanged("EWList"); } } ----- ListItem listItem = new ListItem(e.Message, e.ID);

           //Add a new item only if the message is not empty.
            if (e.Message.Length > 0 )
            {
                if (!EWList.Contains(listItem))
                {
                    EWList.Add(listItem);
                }
            }

}

Model.cs

public List EWList { get; set; }


ListItem.cs public class ListItem { public string Message { set; get; } public string ID { set; get; }

    public ListItem(string message, string id)
    {
        Message = message;
        ID = id;
    }

    public override string ToString()
    {
        return Message;
    }
}
ScenicGA