谁能想到为什么在设计时数据源中使用此特定类会破坏所有设计时绑定? [英] can anyone think of why using this particular class in a design time data source will break all design time bindings?

查看:78
本文介绍了谁能想到为什么在设计时数据源中使用此特定类会破坏所有设计时绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SQLMetal.exe生成了此类.它在运行时具有很强的可绑定性,但是如果我在设计时使用此类,那么我所有的设计时混合绑定都将失效.

I generated this class using SQLMetal.exe. It is very bindable at runtime, but if I use this class at design time, all of my design time blend bindings are busted.

我正在使用MVVM-Light框架,并且正在为WP7构建一个应用程序.

I am using the MVVM-Light framework and I am building an app for WP7.

如果我提取此类的接口,并创建一个实现该接口的简单POCO,然后在设计时数据源中使用我的简单poco,则所有绑定都将生效.

If I extract an interface for this class, and create a simple POCO that implements this interface and I use my simple poco in my design time data source, all of the bindings come alive.

这是SQLMetal.exe生成的类.

Here is the class that was generated by SQLMetal.exe.

[Table(Name="InspectionGroup")]
public partial class InspectionGroup : INotifyPropertyChanging, INotifyPropertyChanged, IInspectionGroup
{

    private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

    private int _InspectionGroupId;

    private string _GroupName;

    private System.DateTime _DateCreated;

    private EntitySet<InspectionHeader> _InspectionHeaders;

    private EntitySet<InspectionPoint> _InspectionPoints;

    #region Extensibility Method Definitions
    partial void OnLoaded();
    partial void OnValidate(System.Data.Linq.ChangeAction action);
    partial void OnCreated();
    partial void OnInspectionGroupIdChanging(int value);
    partial void OnInspectionGroupIdChanged();
    partial void OnGroupNameChanging(string value);
    partial void OnGroupNameChanged();
    partial void OnDateCreatedChanging(System.DateTime value);
    partial void OnDateCreatedChanged();
    #endregion

    public InspectionGroup()
    {
        this._InspectionHeaders = new EntitySet<InspectionHeader>(new Action<InspectionHeader>(this.attach_InspectionHeaders), new Action<InspectionHeader>(this.detach_InspectionHeaders));
        this._InspectionPoints = new EntitySet<InspectionPoint>(new Action<InspectionPoint>(this.attach_InspectionPoints), new Action<InspectionPoint>(this.detach_InspectionPoints));
        OnCreated();
    }

    [Column(Storage = "_InspectionGroupId", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
    public int InspectionGroupId
    {
        get
        {
            return this._InspectionGroupId;
        }
        set
        {
            if ((this._InspectionGroupId != value))
            {
                this.OnInspectionGroupIdChanging(value);
                this.SendPropertyChanging();
                this._InspectionGroupId = value;
                this.SendPropertyChanged("InspectionGroupId");
                this.OnInspectionGroupIdChanged();
            }
        }
    }

    [Column(Storage = "_GroupName", DbType = "NVarChar(100) NOT NULL", CanBeNull = false)]
    public string GroupName
    {
        get
        {
            return this._GroupName;
        }
        set
        {
            if ((this._GroupName != value))
            {
                this.OnGroupNameChanging(value);
                this.SendPropertyChanging();
                this._GroupName = value;
                this.SendPropertyChanged("GroupName");
                this.OnGroupNameChanged();
            }
        }
    }

    [Column(Storage = "_DateCreated", DbType = "DateTime NOT NULL")]
    public System.DateTime DateCreated
    {
        get
        {
            return this._DateCreated;
        }
        set
        {
            if ((this._DateCreated != value))
            {
                this.OnDateCreatedChanging(value);
                this.SendPropertyChanging();
                this._DateCreated = value;
                this.SendPropertyChanged("DateCreated");
                this.OnDateCreatedChanged();
            }
        }
    }

    [Association(Name = "FK_InspectionHeader_InspectionGroup", Storage = "_InspectionHeaders", ThisKey = "InspectionGroupId", OtherKey = "InspectionGroupId", DeleteRule = "CASCADE")]
    public EntitySet<InspectionHeader> InspectionHeaders
    {
        get
        {
            return this._InspectionHeaders;
        }
        set
        {
            this._InspectionHeaders.Assign(value);
        }
    }

    [Association(Name = "FK_InspectionPoint_InspectionGroup", Storage = "_InspectionPoints", ThisKey = "InspectionGroupId", OtherKey = "InspectionGroupId", DeleteRule = "CASCADE")]
    public EntitySet<InspectionPoint> InspectionPoints
    {
        get
        {
            return this._InspectionPoints;
        }
        set
        {
            this._InspectionPoints.Assign(value);
        }
    }

    public event PropertyChangingEventHandler PropertyChanging;

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void SendPropertyChanging()
    {
        if ((this.PropertyChanging != null))
        {
            this.PropertyChanging(this, emptyChangingEventArgs);
        }
    }

    protected virtual void SendPropertyChanged(String propertyName)
    {
        if ((this.PropertyChanged != null))
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    private void attach_InspectionHeaders(InspectionHeader entity)
    {
        this.SendPropertyChanging();
        entity.InspectionGroup = this;
    }

    private void detach_InspectionHeaders(InspectionHeader entity)
    {
        this.SendPropertyChanging();
        entity.InspectionGroup = null;
    }

    private void attach_InspectionPoints(InspectionPoint entity)
    {
        this.SendPropertyChanging();
        entity.InspectionGroup = this;
    }

    private void detach_InspectionPoints(InspectionPoint entity)
    {
        this.SendPropertyChanging();
        entity.InspectionGroup = null;
    }
}

推荐答案

遇到了同样的问题-我相信在desigtime上不支持INotifyPropertyChanging东西,因为该接口旨在简化数据库的工作.由于在设计时没有数据库,所以整个过程都无法让您在Blend中工作(或者在我的情况下是VS xaml可视编辑器)

Just had the same problem - I believe INotifyPropertyChanging stuff is not supported at desigtime, as this interface is designed to make life easier on the database. As there is no DB at designtime, the whole thing fail not letting you work in Blend (or in my case VS xaml visual editor)

对PropertyChanging实施进行注释可以解决此问题.当然,某种形式的预处理器IFDEF会更好,但是那部分不知道.我只是在注释代码

Commenting out PropertyChanging implementation fixes the problem. Of course some sort of pre-processor IFDEF would be better, but no idea on that part.. I just comment the code

这篇关于谁能想到为什么在设计时数据源中使用此特定类会破坏所有设计时绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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