场景:我从我的应用程序主页面开始。我导航到子页面A,更改值,点击后退按钮,主页面中的绑定TextBlock不会更改。如果我导航到子页面B,则使用相同绑定的TextBlock会发生变化。同样,如果我再次访问页面A,我会看到更改后的值。如果我退出应用程序,新的值显示在主页面上。只是在使用后退按钮时,刷新不会被触发。使用MVVM-Light刷新导航返回导航
我已经得到了我所有的INotifyPropertyChanged工作。就像我所说的那样,除了导航返回到主页面外,绑定还可以在每种场景中使用。如何发送消息或以其他方式触发该页面上绑定的刷新?谢谢!
编辑:
基于从willmel接受的答案,这里是我所做的:
我MainPage.xaml中的文件有这个标记:
<TextBlock Text="{Binding Title, Mode=OneWay}" />
我MainViewModel.cs文件有:
public string Title
{
get { return ProfileModel.Instance.DescriptionProfile.Title; }
}
An d我已将此添加到MainViewModel构造:
Messenger.Default.Register<PropertyChangedMessage<string>>(this,
(action) => DispatcherHelper.CheckBeginInvokeOnUI(
() => RaisePropertyChanged("Title")));
另一种观点认为,我有以下的标记:
<TextBox Grid.Row="1" Width="250" Height="100" Text="{Binding TitleEdit, Mode=TwoWay}" />
在其视图模型获取/设置字符串时,我使用这个:
public string TitleEdit
{
get { return ProfileModel.Instance.DescriptionProfile.Title; }
set
{
if (ProfileModel.Instance.DescriptionProfile.Title == value) return;
string oldValue = ProfileModel.Instance.DescriptionProfile.Title;
ProfileModel.Instance.DescriptionProfile.Title = value;
RaisePropertyChanged("Title", oldValue, value, true);
}
}
谢谢!基于此做出更改后,我能够做到我需要的东西。我正在修改我的OP,以显示基于此的一些细节。 – Stonetip 2012-01-14 02:13:00