2011-12-02 91 views
0

我想基於Devexpress數據網格中用於silverlight的數據綁定圖像。 Silverlight的devexpress網格中是否有像rowdatabound這樣的事件?任何幫助將不勝感激。基於數據庫的 布爾值我想顯示所需的圖像。如何在Silverlight的devexpress datagrid中按行綁定數據4

<dxg:GridControl x:Name="gvPaymentCodes" Width="Auto" Grid.Row="2" Grid.Column="0" CustomUnboundColumnData="gvPaymentCodes_CustomUnboundColumnData"> 
     <dxg:GridControl.Columns> 
      <dxg:GridColumn Name="gridColumn1" ReadOnly="True" FieldName="PaymentCode" Header="Current Payment Codes" Width="250" /> 
      <dxg:GridColumn Header="Required" Name="colImageRequired"> 
       <dxg:GridColumn.CellTemplate> 
        <DataTemplate> 
         <Canvas> 
          <Image x:Name="imgRequired" Source="{Binding}" Loaded="imgRequired_Loaded"></Image> 
         </Canvas> 
        </DataTemplate> 
       </dxg:GridColumn.CellTemplate> 
      </dxg:GridColumn>  

感謝

回答

1

您可以使用自定義模板..並可以有條件地更改爲:

public class RowCellTemplateSelector : DataTemplateSelector { 
     public override DataTemplate SelectTemplate(object item, DependencyObject container) { 
      GridCellData cellData = item as GridCellData; 
      FrameworkElement presenter = container as FrameworkElement; 
      if (cellData != null && presenter != null) { 
       if (cellData.Column.FieldName != "UnitPrice") 
        return base.SelectTemplate(item, container); 
       if(Convert.ToDouble(cellData.Value) > 20) 
        return RowCellTemplate1; 
       else 
        return RowCellTemplate2; 
      } 
      return base.SelectTemplate(item, container); 
     } 

檢查此鏈接瞭解詳細信息:如何:Select Templates Based on Custom Logic

這裏是一個樣本也可用d與非綁定數據eals .. 嘗試在未綁定字段使用圖片.. How to: Display Unbound Data

試試這個..希望它幫助你實現。你應該找DXGRid Demo