在EntityObject中的自定义属性上引发PropertyChanged [英] Raise PropertyChanged on custom properties in EntityObject

查看:99
本文介绍了在EntityObject中的自定义属性上引发PropertyChanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在EntityObject上有几个自定义计算的属性。我想触发PropertyChanged事件以通知所有绑定。但是,这不起作用,并且当我使用ReportPropertyChanged时会引发参数异常:

I have several custom calculated properties on an EntityObject. I would like to fire the PropertyChanged event to notify all bindings. This does not work however, and it throws an argumentexception when I use ReportPropertyChanged:


De eigenschap名称heeft geen geldige
entiteitstoewijzing op het
entiteits对象。文档
实体框架的重要性是
信息。

De eigenschap Name heeft geen geldige entiteitstoewijzing op het entiteitsobject. Zie de documentatie van Entity Framework voor meer informatie.

这意味着名称不是实体属性,我应该查看实体框架文档以获取更多信息。有什么方法可以调用事件并使实体框架忽略它?

Which means than Name is not an entity property and I should look in the Entity Framework documentation for more information. Is there any way to call the event and have the Entity Framework ignore it?

代码示例:

partial class Preset
{
    public string Name
    {
        get
        {
            if (this.SystemPreset)
                return Translate("preset_" + this.Name_Original + "_name");
            else
                return this.Name_Original;
        }
        set
        {
            if (!value != this.Name_Internal)
            {
                this.Name_Internal = value;
                ReportPropertyChanged(Name);
            }
        }
    }
}

属性名称是一个自定义属性。当我尝试通过EntityObject中的ReportPropertyChanged方法触发PropertyChanged时,实体框架将引发异常。

The property Name is a custom property. The entity framework will throw an exception when I try to fire PropertyChanged through the method ReportPropertyChanged in EntityObject.

推荐答案

您应该能够只需调用 OnPropertyChanged( YourPropertyName) msdn ),然后从WPF中进行选择。

You should be able to just call OnPropertyChanged("YourPropertyName") (msdn) from your custom property setter and WPF will pick it up.

这在Visual Studio 2010,.NET 4.0中与我对话一个SQLServer CE数据库(我认为它是实体框架4,但不确定)。

This works for me in Visual Studio 2010, .NET 4.0 talking to an SQLServer CE database (I think it's entity framework 4 but I'm not sure).

这篇关于在EntityObject中的自定义属性上引发PropertyChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆