0
我有以下數據庫:http://merc.tv/img/fig/Northwind_diagram.jpg,我想在列表框中顯示所有員工及其圖片。每當我跑我的代碼,我收到一個System.InvalidOperationException在這部分代碼:從數據庫中顯示圖片WPF
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var list = db.Employees;
list.Load();
liemp.ItemsSource = list.Local.OrderBy(l => l.LastName);
}
這是我的WPF代碼:
<Window x:Class="NorthwindWPF.employeeList"
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"
xmlns:local="clr-namespace:NorthwindWPF"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="employeeList" Height="350" Width="300">
<Grid>
<ListBox x:Name="liemp"
DisplayMemberPath="FirstName"
SelectedValuePath="EmployeeID">
<Image Source="{Binding PhotoPath}" />
</ListBox>
</Grid>
</Window>
這是我的類代碼:
namespace NorthwindWPF
{
/// <summary>
/// Interaction logic for employeeList.xaml
/// </summary>
public partial class employeeList : Window
{
NorthwindEntities db = new NorthwindEntities();
public employeeList()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var list = db.Employees;
list.Load();
liemp.ItemsSource = list.Local.OrderBy(l => l.LastName);
}
}
}
出於某種原因,程序凍結,我在圖像路徑現在看起來,我想它們是無效的:HTTP:/ /accweb/emmployees/davolio.bmp – Michael
他不應該使用'ObservableCollection'作爲'liemp'的'DataSource'嗎? – Everyone
@Everyone出於什麼原因?顯然,ItemsSource屬性被設置爲一個固定的集合。除此之外,這裏沒有'DataSource'。 – Clemens