数据表单提交和取消按钮

发布于 2024-10-10 12:31:28 字数 3598 浏览 2 评论 0原文

我在使用 Silverlight 数据表单中的“提交”和“取消”按钮时遇到问题。 起初我不明白为什么当用户单击编辑时取消按钮没有启用。经过一番研究,我发现这是因为该对象不是 IEditableObject。这对取消按钮进行了排序,但现在提交按钮已决定启用,而以前则没有启用,即使在值更改后也是如此。

我的问题是,如何才能启用它?

XAML:

    <dataFormToolkit:DataForm CurrentItem="{Binding ViewModel, ElementName=AccountPage, Mode=TwoWay}" CommandButtonsVisibility="{Binding ViewModel.CommandButtonsVisibility, ElementName=AccountPage, Mode=TwoWay}" AutoEdit="False" AutoGenerateFields="False" AutoCommit="False">
        <dataFormToolkit:DataForm.EditTemplate>
            <DataTemplate>
                <StackPanel>
                    <dataFormToolkit:DataField Label="Organisation Name">
                        <TextBox Text="{Binding Customer.Name, Mode=TwoWay}"/>
                    </dataFormToolkit:DataField>
                </StackPanel>
            </DataTemplate>
        </dataFormToolkit:DataForm.EditTemplate>
    </dataFormToolkit:DataForm>

XAML.cs:

public partial class Account : Page
{
    public VMAccount ViewModel { get; set; }

    public Account()
    {
        InitializeComponent();
    }

    // Executes when the user navigates to this page.
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        ViewModel = new VMAccount(Global.Client.CurrentPerson.Customer);
    }

}

VMAccount:

public class VMAccount : VMBase, IEditableObject
{
    public VMAccount(Customer customer)
    {
        Customer = customer;
    }

    private Customer m_oCustomer;
    public Customer Customer
    {
        get { return m_oCustomer; }
        set
        {
            if (m_oCustomer != value)
            {
                m_oCustomer = value;
                OnPropertyChanged("Customer");
            }
        }
    }

    public event EventHandler<AsyncResultArgs> SaveCustomerSuccess;
    public event EventHandler<AsyncResultArgs> SaveCustomerFailure;

    #region IEditableObject Members

    public void BeginEdit()
    {
        Customer.PropertyChanged += new PropertyChangedEventHandler(OnCustomerPropertyChanged);
        Customer.ContactInfo.PropertyChanged += new PropertyChangedEventHandler(OnCustomerPropertyChanged);
    }

    public void CancelEdit()
    {
        (Customer as IRevertibleChangeTracking).RejectChanges();
        (Customer.ContactInfo as IRevertibleChangeTracking).RejectChanges();
    }

    public void EndEdit()
    {
        if (Customer.HasChanges)
        {
            Global.Client.MainContext.SubmitChanges((lo) =>
            {
                HandleResult("Save Customer", lo, true, SaveCustomerSuccess, SaveCustomerFailure);
            }, null);
        }
    }

    #endregion

    private void OnCustomerPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        OnPropertyChanged("Customer");
    }
}

VMBase:

public class VMBase : INotifyPropertyChanged
{
    protected virtual void OnPropertyChanged(string property)
    {
        if (PropertyChanged != null) 
            PropertyChanged(this, new PropertyChangedEventArgs(property));
    }

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion
}

我放入“OnCustomerPropertyChanged”事件处理程序,看看是否可以强制数据表单承认 Customer 属性已更改,但即使事件正在触发,也没有什么区别。我尝试删除 IEditableObject 以确认这就是问题所在...

public class VMAccount : VMBase//, IEditableObject
...

感谢您的帮助。

编辑:我应该补充一点,客户是 RIA 实体

I'm having trouble with the Commit and Cancel buttons in the dataform for Silverlight.
At first I couldn't figure out why the Cancel button was not enabled when the user clicked edit. After some research I found this was because the object was not IEditableObject. That sorted the cancel button but now the Commit button has decided to become enabled, where it wasn't before, even after the value has changed.

My question is, how do I get it is to be enabled?

XAML:

    <dataFormToolkit:DataForm CurrentItem="{Binding ViewModel, ElementName=AccountPage, Mode=TwoWay}" CommandButtonsVisibility="{Binding ViewModel.CommandButtonsVisibility, ElementName=AccountPage, Mode=TwoWay}" AutoEdit="False" AutoGenerateFields="False" AutoCommit="False">
        <dataFormToolkit:DataForm.EditTemplate>
            <DataTemplate>
                <StackPanel>
                    <dataFormToolkit:DataField Label="Organisation Name">
                        <TextBox Text="{Binding Customer.Name, Mode=TwoWay}"/>
                    </dataFormToolkit:DataField>
                </StackPanel>
            </DataTemplate>
        </dataFormToolkit:DataForm.EditTemplate>
    </dataFormToolkit:DataForm>

XAML.cs:

public partial class Account : Page
{
    public VMAccount ViewModel { get; set; }

    public Account()
    {
        InitializeComponent();
    }

    // Executes when the user navigates to this page.
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        ViewModel = new VMAccount(Global.Client.CurrentPerson.Customer);
    }

}

VMAccount:

public class VMAccount : VMBase, IEditableObject
{
    public VMAccount(Customer customer)
    {
        Customer = customer;
    }

    private Customer m_oCustomer;
    public Customer Customer
    {
        get { return m_oCustomer; }
        set
        {
            if (m_oCustomer != value)
            {
                m_oCustomer = value;
                OnPropertyChanged("Customer");
            }
        }
    }

    public event EventHandler<AsyncResultArgs> SaveCustomerSuccess;
    public event EventHandler<AsyncResultArgs> SaveCustomerFailure;

    #region IEditableObject Members

    public void BeginEdit()
    {
        Customer.PropertyChanged += new PropertyChangedEventHandler(OnCustomerPropertyChanged);
        Customer.ContactInfo.PropertyChanged += new PropertyChangedEventHandler(OnCustomerPropertyChanged);
    }

    public void CancelEdit()
    {
        (Customer as IRevertibleChangeTracking).RejectChanges();
        (Customer.ContactInfo as IRevertibleChangeTracking).RejectChanges();
    }

    public void EndEdit()
    {
        if (Customer.HasChanges)
        {
            Global.Client.MainContext.SubmitChanges((lo) =>
            {
                HandleResult("Save Customer", lo, true, SaveCustomerSuccess, SaveCustomerFailure);
            }, null);
        }
    }

    #endregion

    private void OnCustomerPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        OnPropertyChanged("Customer");
    }
}

VMBase:

public class VMBase : INotifyPropertyChanged
{
    protected virtual void OnPropertyChanged(string property)
    {
        if (PropertyChanged != null) 
            PropertyChanged(this, new PropertyChangedEventArgs(property));
    }

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion
}

I put in the 'OnCustomerPropertyChanged' event handler to see if I could force the dataform to acknoledge the Customer property has changed but it doesn't make a difference, even though the event is firing. I've tried removing the IEditableObject to confirm that this is the problem...

public class VMAccount : VMBase//, IEditableObject
...

Thanks for any help.

EDIT: I should add that Customer is an RIA Entity

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌化 2024-10-17 12:31:28

所以事实证明我正在尝试编辑一个嵌套对象,但在 RIA 工具包 SP1 发布之前无法完成此操作。谢谢。

So it turns out I was trying to edit a nested object which can't be done until RIA toolkit SP1 is released. Thanks.

夜还是长夜 2024-10-17 12:31:28

您的问题可能与问题Silverlight 3 Dataform Commit Button not activate类似

请修改此回复

我也遇到了同样的问题使用 silverlight 4 和 RIA 服务。

我解决了安装 WCF RIA 的问题
服务 Service Pack 1 和
重新安装 WCF RIA 服务
WCF RIA 服务 SP1 工具包。

这两个安装程序可以在以下位置找到:
http://www.silverlight.net/getstarted/riaservices/

直接链接到 WCF RIA 服务 SP 1:
http://go.microsoft.com/fwlink/?LinkId=205085
直接链接到 WCF RIA 服务
WCF RIA 服务 SP1 工具包:
http://go.microsoft.com/fwlink/?LinkID=205088< /p>

You problem can be similar at question Silverlight 3 Dataform Commit Button not activating

Please, revise this response

I had the same isue using silverlight 4 and RIA serivces.

I resolved installing the WCF RIA
Services Service Pack 1 and
re-installing the WCF RIA Services
Toolkit for WCF RIA Services SP1.

This two installer can be found at:
http://www.silverlight.net/getstarted/riaservices/

Direct link to WCF RIA Services SP 1:
http://go.microsoft.com/fwlink/?LinkId=205085
Direct link to WCF RIA Services
toolkit for WCF RIA Services SP1:
http://go.microsoft.com/fwlink/?LinkID=205088

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文