【发布时间】:2016-08-15 16:13:38
【问题描述】:
我在 MVVM light WPF 中将对象传递到辅助视图时遇到问题。我有主视图模型。 follow of operation。我可以使用 MVVM light 和 Modren UI 导航服务来连接。问题是我无法将主要客户视图模型的对象发送到辅助视图模型。我想从源视图模型中设置目标视图的数据上下文。我已经尝试过了,但似乎没有用。我更喜欢没有代码,我花了很多时间都没有成功。
public virtual void NavigateTo(string pageKey, object parameter)
{
lock (_pagesByKey)
{
if (!_pagesByKey.ContainsKey(pageKey))
{
throw new ArgumentException(string.Format("No such page: {0}. Did you forget to call NavigationService.Configure?", pageKey), "pageKey");
}
var frame = GetDescendantFromName(Application.Current.MainWindow, "ContentFrame") as ModernFrame;
// Set the frame source, which initiates navigation
if (frame != null)
{
frame.Source = _pagesByKey[pageKey];
//i Dont know if this should work or not
frame.DataContext = parameter;
}
Parameter = parameter;
_historic.Add(pageKey);
CurrentPageKey = pageKey;
}
}
任何帮助将不胜感激。我只需要如何在不使用代码的情况下设置目标视图的数据上下文。谢谢
【问题讨论】:
标签: c# wpf mvvm-light