如何阻止从更新的绑定属性? [英] How do I stop binding properties from updating?

查看:149
本文介绍了如何阻止从更新的绑定属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在主屏幕上弹出(它实际上是在页面上显示为每比利霍利斯应用程序演示的用户控件)在我的应用程序有从主屏幕中的数据进行编辑的对话框。主屏是只读的。

I have a dialog that pops up over the main screen (it's actually a user control that appears on the page as per the application demo from Billy Hollis) in my application that has data from the main screen to be edited. The main screen is read only.

我的问题是,当我改变对话框中的数据,主屏幕上的更新数据也是如此。显然,他们必然要同一个对象,但有没有办法阻止绑定更新,直到我点击保存我的对话?

The problem I have is that when I change the data in the dialog, the data on the main screen updates as well. Clearly they are bound to the same object, but is there a way to stop the binding update until I click save in my dialog?

推荐答案

您可以使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.data.bindinggroup.aspx\">BindingGroup

...
<StackPanel Name="panel">
    <StackPanel.BindingGroup>
        <BindingGroup Name="bindingGroup"/>
    </StackPanel.BindingGroup>
    <TextBox Text="{Binding Foo}"/>
    <TextBox Text="{Binding Bar}"/>
    <Button Name="btnSubmit" Content="Submit" OnClick="btnSubmit_Click"/>
    <Button Name="btnCancel" Content="Cancel" OnClick="btnCancel_Click"/>
</StackPanel>
...

背后code:

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
    panel.BindingGroup.BeginEdit();
}

private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
    panel.BindingGroup.CommitEdit();
    panel.BindingGroup.BeginEdit();
}

private void btnCancel_Click(object sender, RoutedEventArgs e)
{
    panel.BindingGroup.CancelEdit();
    panel.BindingGroup.BeginEdit();
}

这篇关于如何阻止从更新的绑定属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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