Assuming I have this struct definition in C#:
public struct TimeSlotInfo
{
public int TimeSlotID;
public int StartMin;
public int CalcGridColumn;
public string BackgroundCol;
public bool ToDisable;
}
And I have a linq query as so:
var TimeSlotsInfo =
from ts in datacon.TimeSlots
select new TimeSlotInfo
{
TimeSlotID = ts.TimeSlotID,
StartMin = ts.StartMin,
CalcGridColumn = CalcTimeSlotGridColumn(ts.StartMin),
BackgroundCol = ts.ColorName,
ToDisable = false
};
If i set the ItemsSource property of say a ListBox as below:
lstBox.ItemsSource = TimeSlotsInfo;
Now, how do i set a binding path to reference the “BackgroundCol” field from the above query result?
I’ve tried {Binding Path=TimeSlotInfo.BackgroundCol}, {Binding Path=TimeSlotInfo/BackgroundCol}, and finally {Binding Path=BackgroundCol}…none of them seem to be working..
Can anyone help? I’ve tried to simplify the example as possible. Hope my problem is clear enough.
Thanks in advance.
The last one is correct ({Binding Path=BackgroundCol}) – however, you can’t bind to fields, you can only bind to Properties. Define your class to be: