我有一种情况,我的视图有一个绑定到 ViewModel 的 DataContext,但是我在视图中的一个控件的 DataContext 设置为 ViewModel 的一个属性。第一次更改 ViewModel 时,它会显示更改,但之后,如果我更改 ViewModel 内的属性,则不会将更改反映回视图。
//Somewhere inside my View
<TaicoControl:FlashMessage DataContext="{Binding FlashMessage}"
DockPanel.Dock="Top"
FadesOutAutomatically="True"
FontFamily="BPG Arial"
Message="{Binding Message}"
MessageType="{Binding FlashType}" />
//End of the View
public sealed class ShellViewModel : ViewModelBase
{
public FlashMessageModel FlashMessage { get; private set; }
protected override void SetupEvents()
{
RegisterForEvent<SystemBaloonRequiered>(OnBaloonRequest);
RegisterForEvent<FlashRequest>(OnFlashRequested);
base.SetupEvents();
}
#region Message Handlers
private void OnFlashRequested(FlashRequest obj)
{
FlashMessage = null;
FlashMessage = new FlashMessageModel { Message = obj.Message, FlashType = obj.FlashType };
RaisePropertyChanged(() => FlashMessage);
}
}