Good Day,
I am working on a datagrid in silverlight. I have a WCF service that returns a List that works fine when I populate a datagrid. CoreEmployee returns properties of EmployeeId, FirstName, LastName, HourlyRate, HireDate. This is my XAML of the hourly rate:
<data:DataGridTemplateColumn Header="Hourly Rate">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding HourlyRate}" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
<data:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<!--ItemsSource="{Binding PayRateList, Source={StaticResource PayRateProvider}}"-->
<ComboBox SelectedItem="{Binding HourlyRate}"
ItemsSource="{Binding HourlyRates}"
local:ComboBoxService.ForceOpen="true"
/>
</DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>
</data:DataGridTemplateColumn>
Here is what I am trying to accomplish: When the hourly rates for each employee is populated on the data grid, I also want a list of all the unique salary rates for each person in the data grid.
My code behind does do that:
private List<Decimal> _hourlyRates = new List<decimal>();
public List<Decimal> HourlyRates
{
get { return _hourlyRates; }
}
void client_GetEmployeesCompleted(object sender, GetEmployeesCompletedEventArgs e)
{
try
{
if (e.Result != null)
{
EmployeesGrid.ItemsSource = e.Result;
// Convert an ObservableCollection<T> to a List<T>
List<CoreEmployee> employees = e.Result.ToList<CoreEmployee>();
// Generate a unique list
// http://stackoverflow.com/questions/223400/checking-for-duplicates-in-a-complex-object-using-linq-or-lamda-expression
var results = from item in employees
group item by item.HourlyRate into g
select g.First();
foreach (CoreEmployee employee in results)
{
HourlyRates.Add(employee.HourlyRate);
}
_dataHasLoaded = true;
}
}
catch (Exception exc)
{
// Eat the exception
}
}
However, the problem occurs when I attempt to double click the textblock, the combo box does display, but without any data.
What am I doing wrong?