2016-01-24 69 views
-1

我是新的實體框架,所以我需要幫助。我保存的圖像數據庫(SQL Server),然後我想檢索圖像到一個DataGrid 這裏是我的代碼:我如何檢索圖像從數據庫到WPF的數據網格與EF

using(var contxt=new lotteryEntities1()) 
     { 
      var AllPlayer = contxt.GetAllPlayars(); 
      foreach(var pp in AllPlayer) 
      { 

       string PName = pp.Player_name; 
       string phone = pp.Player_Phone; 
       Photos = ToImage(pp.Photo); 
      } 

      //DTGridEmp.ItemsSource = pp; 
     } 

,這裏是我的XAML代碼:

   <DataGridTemplateColumn Header="Image"> 
        <DataGridTemplateColumn.CellTemplate> 
         <DataTemplate> 
          <Image Source="{Binding Path=Photos}"/> 
         </DataTemplate> 
        </DataGridTemplateColumn.CellTemplate> 
       </DataGridTemplateColumn> 
      </DataGrid.Columns> 
     </DataGrid> 

我從我的實體調用過程,並需要將所有列綁定到數據網格與圖像?

+0

*任何幫助*爲了什麼?你沒有問任何問題! –

+0

這是我的代碼我試圖檢索數據庫中的圖像到datagride –

+1

那麼?你怎麼了?你需要更具體地瞭解你的問題。 –

回答

0

這裏就是答案

List<Players> player = new List<Players>(); 

     using (var contxt = new lotteryEntities1()) 
     { 

      var AllPlayer = contxt.GetAllPlayars(); 

      foreach(var pp in AllPlayer) 
      { 
       player.Add(new Players() { PalyerName = pp.Player_name, PlayerPhone = pp.Player_Phone,Pics=pp.Photo}); 
      } 
      DTGridEmp.ItemsSource = player; 


      // DTGridEmp.ItemsSource = items; 

     } 

而XAML代碼是

<DataGrid x:Name="DTGridEmp" AutoGenerateColumns="False" Margin="0,13,0,0" Width="Auto" Height="Auto" Style="{DynamicResource DataGridStyle1}" ColumnHeaderHeight="40" FlowDirection="RightToLeft" SelectedIndex="0" ColumnWidth=" 243" IsReadOnly="True" SelectionChanged="DTGridEmp_SelectionChanged" PreviewMouseDown="DTGridEmp_PreviewMouseDown"> 
      <DataGrid.Columns> 
       <DataGridTextColumn Header="Name" Binding="{Binding PalyerName}" /> 
       <DataGridTextColumn Header="TelePhone" Binding="{Binding PlayerPhone}" /> 
       <DataGridTemplateColumn Header="Photo" Width="Auto" IsReadOnly="True"> 
        <DataGridTemplateColumn.CellTemplate> 
         <DataTemplate> 
          <Image Source="{Binding Path=Pics}" Width="40" Height="40" /> 
         </DataTemplate> 
        </DataGridTemplateColumn.CellTemplate> 
       </DataGridTemplateColumn> 
      </DataGrid.Columns> 
     </DataGrid> 

感謝所有