我有Northwind數據庫的Employee實體,並且此實體的字段之一是「Photo」,其類型是「Binary」。使用實體框架在Silverlight4 Datagrid中顯示圖像
現在我的問題是我應該如何在Silverlight 4數據網格中顯示「照片」字段,以便我可以查看員工照片?
我需要在我的WCF代碼或我的ModelView代碼中使用待辦事項?
我的XAML代碼如下:
<navigation:Page x:Class="NorthWind.SMS.UI.Views.EmployeeListing"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="EmployeeListing Page" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="50" MaxHeight="50" MinHeight="50" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Height="Auto" HorizontalAlignment="Left" Margin="5,5,0,0" Name="grid1" VerticalAlignment="Top" Width="Auto" />
<TextBlock Grid.Row="0" Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="tbHeader" Text="Employee Listing" VerticalAlignment="Top" FontSize="14" FontFamily="Verdana" TextAlignment="Center" />
<sdk:DataGrid Grid.Row="1" ItemsSource="{Binding Path=Employees}" AutoGenerateColumns="False" Height="Auto" HorizontalAlignment="Left" Margin="5,5,0,0" Name="dgEmployee" VerticalAlignment="Top" Width="Auto" AlternatingRowBackground="{x:Null}">
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn Header="Name">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<Run Text="{Binding EmployeeName.TitleOfCourtesy}"></Run>
<Run Text="{Binding EmployeeName.FirstName}"></Run>
<Run Text="{Binding EmployeeName.LastName}"></Run></TextBlock>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTextColumn Binding="{Binding Path=Title}" Header="Title" />
<sdk:DataGridTextColumn Binding="{Binding Path=HireDate}" Header="HireDate" />
<sdk:DataGridTextColumn Binding="{Binding Path=BirthDate}" Header="DOB" />
<sdk:DataGridTextColumn Binding="{Binding Path=HomePhone}" Header="Phone" />
<sdk:DataGridTextColumn Binding="{Binding Path=City}" Header="City" />
<sdk:DataGridTextColumn Binding="{Binding Path=Region}" Header="Region" />
<sdk:DataGridTextColumn Binding="{Binding Path=Country}" Header="Country" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</Grid>
</navigation:Page>
我的模型視圖代碼如下給出;
private void RefreshEmployees()
{
this.serviceClient.GetEmployeesListingCompleted += (s, e) =>
{
this.Employees = e.Result;
};
this.serviceClient.GetEmployeesListingAsync();
}
所獲得的數據我的WCF的代碼如下顯示;
[OperationContract]
public IEnumerable<Employee> GetEmployeesListing()
{
using (var context = new NorthwindEntities())
{
//context.ContextOptions.LazyLoadingEnabled = false;
var result = context.Employees.ToList();
result.ForEach(e => context.Detach(e));
return result;
}
}