WPF窗口标题绑定基于信息类?(WPF Window Title binding base on Information Class?)

我有Wpf-App用于处理person对象。 Person Struct是Sql-server表,我使用Linq-to-Sql作为我的项目(因此dbml中有类引用person)。

我有更新或插入人员的形式(简单的模态窗口)。 在这个窗口中,我有Peoperty ,它具有当前的人物价值。

public Person CurrentPerson { get; set; }

所以我要寻找的是:

如何绑定此窗口的标题基于CurrentPerson.FullName ? 如果CurrentPerson.FullName已更改,绝对必须更改Window Title!

编辑:更多信息 我想更改基于CurrentPerson.Name窗口标题,而不是设置与CurrentPerson.Name相同。 所以这可能会改变一些事情。 我之前搜索了这个和这个关于改变标题部分的问题 。 但我需要根据价值改变Title的某些部分。

I have Wpf-App for working on person object. Person Struct is Sql-server table and I use Linq-to-Sql for my project(so there is class in dbml refer to person).

I have form for update or inserting persons(simple modal window). In this window I have Peoperty which have current value of person.

public Person CurrentPerson { get; set; }

So what I look for is :

How bind title of this window base on CurrentPerson.FullName? and absolutely Window Title must change if CurrentPerson.FullName Changed!

Edit: More Info I want to change window title base on CurrentPerson.Name not set equally same as CurrentPerson.Name. So this might be change something. Also I searched before find this and this Question about changing part of Title. but I need to change some part of Title base on value.

最满意答案

首先,您的codebehind或viewmodel应该实现INotifyPropertyChanged 。 之后,实现一个属性WindowTitle如下所示:

public string WindowTitle { get { return "Some custom prefix" + CurrentPerson.FullName; } }

在此之后,每当您更改CurrentPerson上的FullName时,只需抛出PropertyChanged事件,例如:

Person _currentPerson; public Person CurrentPerson { get { return _currentPerson; } set { _currentPerson = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("WindowTitle")); } }

编辑:请发布你的xaml代码的绑定,看看你对新手的帖子的评论,似乎是罪魁祸首。 另外,检查您是否将Window的DataContext为自身。

Firstly, your codebehind or viewmodel should implement INotifyPropertyChanged. After that, implement a property WindowTitle like this:

public string WindowTitle { get { return "Some custom prefix" + CurrentPerson.FullName; } }

After this, whenever your change the FullName on your CurrentPerson, just throw a PropertyChanged event, for example:

Person _currentPerson; public Person CurrentPerson { get { return _currentPerson; } set { _currentPerson = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("WindowTitle")); } }

EDIT: Please post your xaml code for the binding, which looking at your comment on the post of Novice, seems like the culprit. Also, check that you are setting the Window's DataContext to itself.

WPF窗口标题绑定基于信息类?(WPF Window Title binding base on Information Class?)

我有Wpf-App用于处理person对象。 Person Struct是Sql-server表,我使用Linq-to-Sql作为我的项目(因此dbml中有类引用person)。

我有更新或插入人员的形式(简单的模态窗口)。 在这个窗口中,我有Peoperty ,它具有当前的人物价值。

public Person CurrentPerson { get; set; }

所以我要寻找的是:

如何绑定此窗口的标题基于CurrentPerson.FullName ? 如果CurrentPerson.FullName已更改,绝对必须更改Window Title!

编辑:更多信息 我想更改基于CurrentPerson.Name窗口标题,而不是设置与CurrentPerson.Name相同。 所以这可能会改变一些事情。 我之前搜索了这个和这个关于改变标题部分的问题 。 但我需要根据价值改变Title的某些部分。

I have Wpf-App for working on person object. Person Struct is Sql-server table and I use Linq-to-Sql for my project(so there is class in dbml refer to person).

I have form for update or inserting persons(simple modal window). In this window I have Peoperty which have current value of person.

public Person CurrentPerson { get; set; }

So what I look for is :

How bind title of this window base on CurrentPerson.FullName? and absolutely Window Title must change if CurrentPerson.FullName Changed!

Edit: More Info I want to change window title base on CurrentPerson.Name not set equally same as CurrentPerson.Name. So this might be change something. Also I searched before find this and this Question about changing part of Title. but I need to change some part of Title base on value.

最满意答案

首先,您的codebehind或viewmodel应该实现INotifyPropertyChanged 。 之后,实现一个属性WindowTitle如下所示:

public string WindowTitle { get { return "Some custom prefix" + CurrentPerson.FullName; } }

在此之后,每当您更改CurrentPerson上的FullName时,只需抛出PropertyChanged事件,例如:

Person _currentPerson; public Person CurrentPerson { get { return _currentPerson; } set { _currentPerson = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("WindowTitle")); } }

编辑:请发布你的xaml代码的绑定,看看你对新手的帖子的评论,似乎是罪魁祸首。 另外,检查您是否将Window的DataContext为自身。

Firstly, your codebehind or viewmodel should implement INotifyPropertyChanged. After that, implement a property WindowTitle like this:

public string WindowTitle { get { return "Some custom prefix" + CurrentPerson.FullName; } }

After this, whenever your change the FullName on your CurrentPerson, just throw a PropertyChanged event, for example:

Person _currentPerson; public Person CurrentPerson { get { return _currentPerson; } set { _currentPerson = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("WindowTitle")); } }

EDIT: Please post your xaml code for the binding, which looking at your comment on the post of Novice, seems like the culprit. Also, check that you are setting the Window's DataContext to itself.