Silverkight 5 datagrid image size

Normally our image can be different size when we upload the. if we want to fixed that all image size will be fixed in Silver light 5 Data grid.like this




XAML Binding for image:

  <sdk:DataGridTemplateColumn Header="Color image" Width="6*" IsReadOnly="True" >  
             <sdk:DataGridTemplateColumn.CellTemplate >   
               <DataTemplate>  
                 <Image Source="{Binding Path=ColorImageFile}" Stretch="Fill" Width="100" Height="60" Visibility="Visible"/>  
               </DataTemplate>  
             </sdk:DataGridTemplateColumn.CellTemplate>  
           </sdk:DataGridTemplateColumn>  

on datagrid onloading event. set the image column with your class image attribute. here it is ColorImageFile

  private void DgReceiveBuyerComment_OnLoadingRow(object sender, DataGridRowEventArgs e)  
     {  
       try  
       {  
         BO.LAB_LDCommentReceipt labLdCommentObj = e.Row.DataContext as BO.LAB_LDCommentReceipt;  
         if (labLdCommentObj != null)  
         {  
           FrameworkElement ele = dgReceiveBuyerComment.Columns[4].GetCellContent(e.Row);  
           (ele as Image).Source =  
             new BitmapImage(new Uri(GlobalVar.ImagePath + labLdCommentObj.ColorImageFile,  
                         UriKind.RelativeOrAbsolute));  
         }  
       }  
       catch (Exception ex)  
       {  
         throw ex;  
       }  
     }  

you also have to use this dll

 using System.Windows.Controls;  
 using System.Windows.Media.Imaging;  

Popular posts from this blog

mvc razor textboxfor change event change another textboxfor value

WPF Crystal Report Viewer Using SAP

ASP.NET MVC razor SAP Crystal report