结合目标的更新 [英] update of binding target

查看:81
本文介绍了结合目标的更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用不同的文本框创建了一个用户界面.我将文本框绑定到一个数据对象,该数据对象表示一个姓为...的人.

I created an user interface with different textboxes. I bound the textboxes to a data object that represents a person with surname, first name ....

XAML:

< 名称 ="tbSurname"" 文本 =&; { 路径 = Surname}">

<TextBox Name="tbSurname" Text="{Binding Path=Surname}">

< 名称 ="tbFirstName" 文本 =&; { 路径 = FirstName}">

<TextBox Name="tbFirstName" Text="{Binding Path=FirstName}">

C#:

公共无效SetPerson(人p)

public void SetPerson( Person p)

{

   mIgnoreChanges = true;

    mIgnoreChanges = true;

   tbSurname.DataContext = p;

    tbSurname.DataContext = p;

   tbFirstName.DataContext = p;

    tbFirstName.DataContext = p;

    mIgnoreChanges = false;

}

监视文本框的任何更改并如果发生更改标志,则将其设置.如果显示一个新的Person,但是没有显示,则调用方法'SetPerson' 数据已更改.因此,我想通过mIgnoreChanges标志的方法来防止设置Changed标志.但这是行不通的,因为文本框是在更新之后 SetPerson已完成.因此,我没有机会在实际数据更改(可能由用户引起,但有时也由应用程序引起)与仅切换显示数据的更改之间保持差异.怎么能 我解决了这个问题吗?

Any changes of the textboxes are monitored and a Changed-Flag is set if they occur. The method 'SetPerson' is called if a new Person is displayed but no data changed. So I wanted to prevent setting of the Changed flag by means of the mIgnoreChanges flag. But this doesn't work because textboxes are updates after SetPerson is finished. So I have no chance to differ between real data changes (maybe caused by the user, but sometimes also caused by the application) and changes that only switch displayed data. How can I solve this problem?

推荐答案

_More _,

Hi _More_,

根据我对您的问题的了解,我认为您可以参考" WPF DataBind "和" INotifyPropertyChanged ",我认为您的问题可以解决:

Based on my understand of your problem, I think you could refer to "WPF DataBind" and "INotifyPropertyChanged", after refer this, I think your issue could be resolved:

http://msdn.microsoft.com/en-us/library/ms750612.aspx              ( WPF DataBind )

http://msdn.microsoft.com/en-us/library/ms750612.aspx               (WPF DataBind)

http://msdn.microsoft.com/en-us/library/ms752347.aspx nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; ( WPF DataBind )

http://msdn.microsoft.com/en-us/library/ms752347.aspx                (WPF DataBind)

http://msdn.microsoft.com/en-us/magazine/cc163299.aspx             ( WPF DataBind )

http://msdn.microsoft.com/en-us/magazine/cc163299.aspx             (WPF DataBind)

就您而言,我认为" INotifyPropertyChanged "对您来说更重要,因为这正是您所需要的,它可以直接解决您的问题,

In your case, I think "INotifyPropertyChanged" is more important to your, because it is what you need, and it could resolve your issue directly,

http://msdn.microsoft.com/en-us/library/system .componentmodel.inotifypropertychanged.aspx

http://msdn.microsoft.com/en-us/library/ms229614.aspx

另一方面 ,您的问题的另一种解决方案是名为" DataContextChanged ",用于 您可以参考更多详细信息:

On the other hand, another solution of your issue is an event named "DataContextChanged", for more details you could refer to:

http://msdn.microsoft.com/en-us/library /system.windows.frameworkelement.datacontextchanged.aspx

 

最好的问候


这篇关于结合目标的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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