Hello
I'm developing silverlight application using wcf data service and radgridview. From wcf dataservice I get collection of objects TimesheetWeekSummary.
[DataContract] public class TimesheetWeekSummary { [DataMember] public WorkingDay[] WorkingDays; // other properties [DataContract] public class WorkingDay { [DataMember] public DateTime Date { get; set; } [DataMember] public decimal? Hours { get; set; } [DataMember] public bool IsApproved { get; set; } } }Now I want to bind each object of WorkingDays array to different RadGridView columns, corresponding to each day of the week (WorkingDays contains 7 elements). Fyi I'm creating columns dynamically. In each cell I want to display Date in one line and Hours in another. I've written a template to do so:
<DataTemplate x:Name="DayCellTemplate" x:Key="DayCell"> <StackPanel Orientation="Vertical"> <TextBlock Text="{Binding Date, StringFormat='yyyy/MM/dd' }" /> <TextBlock Text="{Binding Hours}" /> </StackPanel> </DataTemplate>And here is example of how the columns are created:
WorkingDayConverter converter = new WorkingDayConverter(); radGridView.Columns.Add(new GridViewDataColumn() { UniqueName = Columns.Monday.ToString(), Header = columnHeaders[Columns.Monday], DataMemberBinding = new System.Windows.Data.Binding() { Converter = converter, ConverterParameter = (int)DayOfWeek.Monday }, CellTemplate = (DataTemplate)LayoutRoot.Resources["DayCell"], Width = 100, IsResizable = false, IsReadOnly = true});Converter code seems fine:
public class WorkingDayConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { int param = (int)parameter; if (value == null || param < 0 || param > 6) return null; TimesheetWeekSummary weekSummary = (TimesheetWeekSummary)value; return weekSummary.WorkingDays[param]; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } }This solution is unfortunately not working, grid cells are empty and the object binded to the data template is TimesheetWeekSummary (I can display it's properties if I change the template).
Any help would be greatly appreciated.