请考虑以下DataModel
由于我是新来的,所以我无法发布图片,所以我会尝试另一种方法......
职位实体 -jobid -jobNo -jobStatus(来自Status实体的外键) -jobDate
状态实体 -statusId -statusCaption
关系 工作实体* ----------- 0..1状态实体
我有一个WCF服务,它公开了我的JobsViewModel
访问的模型namespace PM.DataService
{
[ServiceContract]
public class PMService
{
[OperationContract]
public ObservableCollection<Job> GetAllJobs()
{
using (var context = new logisticDBEntities())
{
var result = context.Jobs.ToList();
result.ForEach(e => context.Detach(e));
return new ObservableCollection<Job>(result);
}
}
[OperationContract]
public ObservableCollection<Status> GetStatuses()
{
using (var context = new logisticDBEntities())
{
var result = context.Statuses.ToList();
result.ForEach(e => context.Detach(e));
return new ObservableCollection<Status>(result);
}
}
}
}
namespace PM.UI.ViewModel
{
public class JobsViewModel:INotifyPropertyChanged
{
private PMServiceClient serviceClient = new PMServiceClient();
public JobsViewModel()
{
this.RefreshStatuses();
this.RefreshAllJobs();
}
private void RefreshAllJobs()
{
this.serviceClient.GetAllJobsCompleted += (s, e) =>
{
this.allJobs = e.Result;
};
this.serviceClient.GetAllJobsAsync();
}
private void RefreshStatuses()
{
this.serviceClient.GetStatusesCompleted += (s, e) =>
{
this.Statuses = e.Result;
};
this.serviceClient.GetStatusesAsync();
}
private ObservableCollection<Job> allJobs;
public ObservableCollection<Job> AllJobs
{
get{
return this.allJobs;
}
set
{
this.allJobs = value;
OnPropertyChanged("AllJobs");
}
}
private ObservableCollection<Status> statuses;
public ObservableCollection<Status> Statuses
{
get
{
return this.statuses;
}
set
{
this.statuses = value;
this.OnPropertyChanged("Statuses");
}
}
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
我在我的MainWindow的xaml中包含了JobsViewModel
<Window x:Class="PM.FullClient.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PM.UI"
xmlns:vms="clr-namespace:PM.UI.ViewModel"
Title="MainWindow" Height="475" Width="575">
<Window.DataContext>
<vms:JobsViewModel/>
</Window.DataContext>
....
现在我可以通过绑定轻松填充MainWindow上的DataGrid以显示所有状态
<DataGrid ItemsSource="{Binding Path=Statuses}" Margin="7,8,9,8" AutoGenerateColumns="True">
它有效,但我无法显示输出cos我无法在此处发布图像
但是当我尝试与乔布斯做同样的事情时......什么都没发生。 数据网格是空的
<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding Path=AllJobs}" Margin="6">
</DataGrid>
我经历过许多搜索了大量的四分之一和网站的menthods,最后我就在这里。
可能是状态&gt;的cos工作和状态之间的工作关系?如果是这样我怎么能解决这个问题,如果不是我做错了什么?
答案 0 :(得分:3)
问题是,在RefreshAllJobs()回调中,您设置 allJobs 字段(小写'a'),而不是 AllJobs 属性(更高级别)大小写'A'),然后OnPropertyChanged()永远不会从属性 setter调用。