I am new to WPF. I have a listBox with various elements graphics elements in it. The element in the listBox are linked to a list.
At the moment to add elements I am doing it the old way that is with no binding:
StackPanel sp = new StackPanel();
string currentDir = AppDomain.CurrentDomain.BaseDirectory.ToString();
TextBox tb = new TextBox()
{
Text = strContent,
BorderBrush = new SolidColorBrush(Colors.Gainsboro),
IsReadOnly = true,
ToolTip = strNotes,
FontSize = 12,
FontWeight = FontWeights.Bold,
Width = IMAGES_ROW_HEIGHT,
Height = IMAGES_ROW_HEIGHT / GOLDEN_RATIO,
Background = null,
Margin = new Thickness(BUTTON_MARGIN),
VerticalContentAlignment = VerticalAlignment.Center,
HorizontalContentAlignment = HorizontalAlignment.Center
};
sp.Children.Add(tb);
Image newResizedImage = ImageUtilities.StrPath2ResizedImageSizeHeight(strPathImage, IMAGES_ROW_HEIGHT);
if (newResizedImage != null)
{
sp.Children.Add(newResizedImage);
sp.Orientation = Orientation.Horizontal;
sp.HorizontalAlignment = HorizontalAlignment.Left;
}
lbxPPgroups.Items.Add(sp);
lbxPPgroups.SelectedIndex = 0;
var newGroup = new PcDmisData.Group();
newGroup.Description = strContent;
var newImage = new PcDmisData.MyImage();
newImage.Image = newResizedImage;
newImage.IsImageEmbedded = false;
newGroup.myImage = newImage;
newGroup.Notes = strNotes;
easyRunData.olstPPgroups.Add(newGroup);
but I know I'm doing it wrong, because I'll have to manually handle deletion, add, reorder of element and so on. I Would like to be able to bind the elements in the listBox to the elements of the following class:
[Serializable]
public class EasyRunXmlSerializableData
{
public EasyRunXmlSerializableData()
{ }
//PcDmis Data
public ObservableCollection<PcDmisData.Group> olstPPgroups = new ObservableCollection<PcDmisData.Group>();
}
with
public class PcDmisData
{
[Serializable]
public class Group
{
public string Description;<---------this for the text of the textbox
public MyImage myImage;<------------this is the image
public string Notes;<---------------this for a tooltip
public ObservableCollection<PartProgram> partProgramList = new ObservableCollection<PartProgram>();
}
[Serializable]
public class MyImage
{
public object Image;
public bool IsImageEmbedded;
}
....
thanx for any help Patrick

DataTemplatefor your view model type (or types) that bind to the appropriate properties in the view model class and present the desired appearance according to the values in those properties.