使用Linq to SQL并必须更新“保存"消息.按钮 [英] Using Linq to SQL and Have to Update a "Save" button

查看:52
本文介绍了使用Linq to SQL并必须更新“保存"消息.按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有数据绑定功能的Windows Forms应用程序(是的,我知道,现在就枪杀我),它有一个保存"工具栏按钮.我想将保存"按钮显示为灰色,除非用户对将更改DataContext上属性的表单控件进行了更改.

该表具有100的属性,所以我不想实现

I have a Windows Forms app with databinding (yes, I know, shoot me now) and it has a "Save" toolbar button. I want to gray out the "Save" button unless the user has made a change to the form control that will change a property on the DataContext.

The table has 100''s of properties so I don''t want to implement

partial void OnXXXChanged(XXX value)
{

}



一遍又一遍地.我的想法是向DataContext子类中添加一个委托,并可能向一个轮询线程添加一个检查属性,并询问是否已对其进行更改.

DataContext似乎实现了INotifyPropertyChanged等,但是我似乎无法绑定到模型中的PropertyChanged事件.

从本质上讲,我该如何检测条件嘿!您需要调用SubmitChanges()弯身!"并在发生这种情况时收到通知,以便我可以取消对保存按钮的显示?



over and over again. My thought was to add a delegate to the DataContext partial class and maybe a polling thread to check the properties and ask if they''ve been changed.

DataContext appears to implement INotifyPropertyChanged etc but I can''t seem to tie onto the PropertyChanged event from my Model.

How can I detect, essentially, the condition "hey! you need to call SubmitChanges() stoop!" and get a notification when that happens so I can un-gray the save button?

推荐答案

* Nevermind *

一种方法是完全破解

*Nevermind*

One way, a total hack is to do

partial class DbDataContext
{
    public bool IsDirty { get; set; }

    partial void OnCreated()
    {
        Application.Idle += (sender, e) =>
        {
            ChangeSet set = GetChangeSet();

            IsDirty = set.Inserts.Count > 0 || set.Updates.Count > 0 
                 || set.Deletes.Count > 0;
        };
    }
}



当然还要更新Application.Idle上的保存"按钮.



And of course also update the Save button on Application.Idle.


这篇关于使用Linq to SQL并必须更新“保存"消息.按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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