0

I am trying to implement a cell template for a datagrid.  The problem is, when I try to bind to the Object within the datagridview, I am not getting the values that I am expecting.

 

This is what the datagrid looks like with no styling:

datagrid plain

 

Pretty simple, but when I try to style it using a cell template with triggers, this is what I am getting (Each cell that has DAL.Task above should contain an orange circle):

datagrid styled

 

here is the xaml that I am using to style the grid: 

 

<DataTemplate x:Key="MiddleDataGridCellTemplate">
 <Grid>
  <Image Name="CenterImage"
   HorizontalAlignment="Center"
   VerticalAlignment="Center"/>     
 </Grid>
 <DataTemplate.Triggers>
  <DataTrigger Binding="{Binding Row.ItemArray/TaskStatusName}"
   Value="In Progress">
   <Setter TargetName="CenterImage"
    Property="Source"
    Value="/besoControlLibrary;component/Resources/Spreadsheet_CheckedOut.png" />
  </DataTrigger>
 </DataTemplate.Triggers>
</DataTemplate>

 

I am guessing that "{Binding Row.ItemArray/TaskStatusName}" is causing the problem, what is the correct way to pull out the TaskStatusName property of the DAL.Task within the datagridview?

I found out that the values of the blank cells are DBNull if that helps at all.

 

Also, these values are coming from a DataTable that is the context of the the DataGrid.



Deus Duke
  • 93
  • 1
  • 10

2 Answers2

1

The DataContext should already be your object you are showing so you should be able to bind right to whatever property you want:

{Binding TaskStatusName}

You can get more information from looking at your output window when running your app. Also here is an example of a DataGridTemplateColumn which is probably what you want to mimic:

http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridtemplatecolumn%28v=vs.95%29.aspx

Matt West
  • 2,874
  • 1
  • 19
  • 13
  • This is the output when I do what you suggest: System.Windows.Data Error: 40 : BindingExpression path error: 'TaskStatusName' property not found on 'object' ''DataRowView' (HashCode=15157836)'. BindingExpression:Path=TaskStatusName; DataItem='DataRowView' (HashCode=15157836); target element is 'ContentPresenter' (Name=''); target property is 'NoTarget' (type 'Object') – Deus Duke May 09 '11 at 21:50
0

I solved the problem, the solution is here:

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7fe562f4-739c-45df-bea3-557abd80c63d

Deus Duke
  • 93
  • 1
  • 10